Wmic exception occured

Posted on 6th February 2014 in Windows Server

Some time ago we have faced problem that our script which calls wmic to get some values stopped to work. After a short research we have found that on some servers wmic utility stopped to work, showing exception every time we run any command:

wmic os get caption
Description = Exception occurred.

In the same time wbemtest and powershell worked correctly. The solution was to add “/value” switch to a command:

wmic os get caption /value
Caption=Microsoft Windows Server 2008 R2 Enterprise

For some reason wmic can’t format output as a table (the same error you can get with /format: table switch and get rid of it with /format:list), which is default, or can be done with /all switch. Hope this helps someone.

comments: 0 » tags: ,

Find all VMWare VMs created in a given period

Posted on 15th January 2014 in Uncategorized

To find all virtual machines created in a given period use the following SQL script:

select ev.CREATE_TIME, EV.VM_NAME AS OldName
Where (EV.event_type = ‘vim.event.VmDeployedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VmCreatedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VMClonedEvent’) AND EV.CREATE_TIME >= cast(‘01.01.2013′ AS DATETIME) AND EV.CREATE_TIME <= cast(‘31.01.2014′ AS DATETIME)

Output of this script will show all created VMs including deleted ones. To show only existing virtual machines you can use following SQL script:

Where EV.VM_ID=INF.ID AND (EV.event_type = ‘vim.event.VmDeployedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VmCreatedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VMClonedEvent’) AND EV.CREATE_TIME >= cast(‘01.01.2013′ AS DATETIME)

As you can see it can help you to find renamed virtual machines as well. One of the biggest problem of this script is that it relies on events, which can be deleted by time when you run script. Unfortunately it is impossible to find the same data any other way. The only other solution is to use custom fields, which have to be created to the moment of need.

select ev.CREATE_TIME, EV.VM_NAME AS OldName
Where (EV.event_type = ‘vim.event.VmDeployedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VmCreatedEvent’ OR EV.EVENT_TYPE = ‘vim.event.VMClonedEvent’) AND EV.CREATE_TIME >= cast(‘01.01.2013′ AS DATETIME) AND EV.CREATE_TIME <= cast(‘31.01.2014′ AS DATETIME)

comments: 0 »

Restoring MSSQL database to new location from command line with IBM TSM

Posted on 10th January 2014 in Uncategorized

Just a simple commands sequence with comments.

tdpsqlc.exe q tsm SOURCE_DB_NAME f /all

write down Database Object Name for needed full backup.

If you want to recover database backed up with options from dsm.opt file use following command:


If you want to recover database backed up with options different from dsm.opt, use following:

tdpsqlc restore SOURCE_DB_NAME full /into=DESTINATION_DB_NAME /RELocate=DATA_FILE_NAME,LOG_FILE_NAME /to=PATH_TO_DATA_FILE.mdf,PATH_TO_LOG_FILE.ldf /RECOVery=no /replace /object=DATABASEOBJECTNAME /tsmoptfile=other.opt

tdpsqlc.exe q tsm SOURCE_DB_NAME diff /all

Write down Database Object Name for needed diff backup


tdpsqlc.exe q tsm SOURCE_DB_NAME log=* /all

Write down Database Object Names for all needed log backups


…repeat for all needed logs


Do not forget to add recovery=yes to last restored log.

comments: 0 »

Listing all MSSQL performed for specific database

Posted on 10th January 2014 in Backup, MSSQL

Yesterday I’ve stuck with restoring some MSSQL database, because of incompatibility between used differential and full backups, after I’ve found correct full backup, restore process completed without any problem. The following error identifies that:

The log or differential backup cannot be restored because no files are ready to rollforward

The following script helped me to find out correct backup chain:

TOP 100o
CASE s.type
WHEN ‘D’ THEN ‘Full’
WHEN ‘I’ THEN ‘Differential’
WHEN ‘L’ THEN ‘Transaction Log’
END AS BackupType,
CAST(DATEDIFF(second, s.backup_start_date,
s.backup_finish_date) AS VARCHAR(4)) + ‘ ‘ + ‘Seconds’ TimeTaken,
CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn,
CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn,
CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ‘ ‘ + ‘MB’ AS bkSize,
FROM msdb.dbo.backupset s
INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
WHERE s.database_name = DB_NAME() — Remove this line for all the database
ORDER BY backup_start_date DESC, backup_finish_date

You might want to replace TOP 100o with bigger value if you have a lots of backups.

comments: 0 » tags: , ,

Enable Text Console (SOL) on Windows Server 2012

Posted on 10th January 2014 in Windows Server

After installing Windows 2012 on old Fujitsu Primergy RX200 we lost ability to manage it with serial console. We’ve even tried to update iRMC firmware with no luck. Problem was resolved after we enabled EMS (Emergency Management Services) with the following set of commands:

BCDedit /bootems {Boot_entry_id} ON

bcdedit /ems on

bcdedit /emssettings EMSPORT:2 EMSBAUDRATE:115200

Ensure that you’ve changed Boot_entry_id to your ID (you can get it with bcdedit /v), 2 to your COM port number (you can get it from your bios settings, or from irmc settings) and 115200 to your bauderate (you can get it from your bios settings, or from irmc settings).

Reboot and enjoy serial access to your server.

comments: 0 » tags: , , ,

Find all active AD users not expiring in a month

Posted on 23rd December 2013 in Active Directory, Windows Server

Sometimes your AD has a lots of temporary users, with accounts expiring in near future, and to ensure that only legitimate users have never expiring or long expiring accounts you want to audit your accounts. To do so, perform next:
1. Create test account expiring today
2. With ADSI edit get the value of accountExpires property
3. Add to this value Number_of_days*864000000000, write down this value (actually you can create test account expiring on required date, but it is not so fun)
4. Run the following command:
dsquery * -filter “(&(objectCategory=person)(objectClass=user)(accountExpires>=130344624000000000)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))”
where 130344624000000000 is the number from step 3
and !(userAccountControl:1.2.840.113556.1.4.803:=2) means that we only want to find enabled users.


In some cases users with expire date “Never” have accountExpires=9223372036854775807 but in some cases it is equal to 0. So, correct search query will be:

dsquery * -filter “(&(objectCategory=person)(objectClass=user)(|(accountExpires>=130720500000000000)(accountExpires=0))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))” -limit 1000

comments: 0 » tags: ,

Unexpected server reboot caused by windows update

Posted on 19th December 2013 in Uncategorized

Recently I’ve got unexpected Windows server 2008 R2 reboot with some recovery reason, which is quite uninformative:

The process C:\Windows\system32\svchost.exe (servername) has initiated the restart of computer servername on behalf of user NT AUTHORITY\SYSTEM for the following reason: Operating System: Recovery (Planned)
Reason Code: 0x80020002
Shutdown Type: restart

As time of reboot was very close to 03:00 AM (default windows update installation time) and System event log contained couple of events about update installation, I’ve decided to check WindowsUpdate.log file.

It has following:

2013-12-16    03:17:06:606     832    13c8    AU    AU invoking RebootSystem (OnRebootNow)
2013-12-16    03:17:06:647     832    13c8    Misc    WARNING: SUS Client is rebooting system.
2013-12-16    03:17:06:647     832    13c8    AU    AU invoking RebootSystem (OnRebootRetry)
2013-12-16    03:17:06:651     832    13c8    AU    AU received handle event

So to eliminate such unexpected reboots disable automatic updates for production servers, or deny it automatically reboot server.

comments: 1 »

TSM Active Data pool file number

Posted on 19th December 2013 in Backup, TSM

One of the strange features of TSM AD pool is that, when you do first incremental backup (for example 10 files), then change some data (for example 5 files) you’ll get incorrect number of files with query occupancy stg=adpool command. It will show you number of files equal to 15, the same as in your primary storage pool. But if you compare sizes of pool you’ll see a difference.  So do not rely only on file number in your AD storage pool

comments: 0 » tags: ,

Clustered MS SQL dependency on mounted volume

Posted on 14th November 2013 in Uncategorized

Recently I have added new mounted volume to Microsoft cluster (lets say disk 3 mounted at m:\history), and tried to restore some old backup to it. But after I have run SQL script I’ve immediately got an SQL error:
Only formatted files on which the cluster resource of the server has a dependency can be used. Either the disk resource containing the file is not present in the cluster group or the cluster resource of the SQL Server does not have a dependency on it.
After short searches I’ve found couple of links stating than I need to add my volume to clustered MS SQL service dependencies to operate with this volume. By the way Microsoft’s manuals does not clarify do you really need to bring clustered MS SQL server offline before adding new dependency or not. One instruction says that you should to do so and others say that you can just add new dependency without interruption.
But after I’ve tried to follow this instruction the problem have not gone, and script showed the same error. I’ve tried to add source file’s drive (lets say disk 2 mounted to m:\backups) to dependencies as well without luck. The error was resolved only after I’ve added “root” volume M:. But this volume was previously added to original disk dependencies, so disk 3 mounted at m:\history was dependent on disk 1 (M:). So it seems clustered MS SQL does not look through dependency chain and just tests the drive which starts the file path, without worrying about real dependent volume. Hope this will save your time.

comments: 0 » tags: ,

vSphere Client and space key

Posted on 13th November 2013 in Uncategorized

Recently we have had a very confusing incident while trying to access one of our production virtual server through vSphere client. As linux servers in default installation redraw its console only on some event (some input or output), every time we open virtual machine with linux to see its console we need to press some key on keyboard. The problem is when you just opened console in the thick client user’s input focused on the toolbar. More precisely on its first button, which is “Shutdown”. When you press this button you’ll get confirmation dialog and input focus is on the “OK” button again. So if just opened server console, without clicking mouse anywhere, and quickly press space key two times, it will immediately shutdown you server, which will cause unplanned downtime to your production system. Very disappointing application design for industry’s leader solution. By the way, vSphere webclient doesn’t have such problems.

comments: 0 » tags: ,