10 October 2014

How to find duplicate MAC addresses in SCVMM 2012 R2

Sometimes, when you move virtual machine from one host to another you can run into duplicate MAC address problem. Of course you can have other scenarios for that situation to happen, for example two hyper-v hosts sharing the same MAC address range etc.

If you have searched for solutions on the internet, you won’t be happy with them. At least I wasn’t. Because I didn’t see the VM name in the results.

So I invested some time and came up with that PowerShell script:

cls
Import-Module virtualmachinemanager
"Working..."
$result = Get-VM | foreach {
foreach ($nic in $_.VirtualNetworkAdapters) {
    $obj = new-object psobject
    $obj | add-member noteproperty Host ($_.Name)
    $obj | add-member noteproperty Type ($nic.MACAddressType)
    $obj | add-member noteproperty MAC ($nic.MACAddress)
    $obj
    }
}
"Done"
$result | sort MAC | ConvertTo-Csv -Delimiter `t -NoTypeInformation | clip

This will get all VM-s, go through each of them and display each virtual network adapters MAC address with the server name. This script will place the results in clipboard for easy pasting and analyzing in Excel.

image

19 August 2014

How to change time zone from command line

Sometimes you have an installation from network server (Windows Deployment Services) and you find that time zone is not selected correctly. Or you just forgot to select the correct one when installing from optical media.

Since Windows Vista/2008 you can use tzutil.exe utility from command line to do time zone related things.

You can script to change the time zone change. For example if you have site based logon scripts and your site is in a single time zone, you can add it to site specific Group Policy Object (GPO).

First take a list of available time zones with the tzutil /l command:

image

My time zone is with name FLE Standard Time, so to change the time zone to this one, I use the command tzutil /s "FLE Standard Time"

image

To check the new time zone, use tzutil /g command:

image

06 May 2014

How to force from Windows Update to Microsoft Update

If you are not satisfied with Windows Update (updates for Windows only) and need other updates for Exchange SQL etc, then you need to switch to Microsoft Update.

I was not able to find this option on Control Panel (Windows Server 2012 computer)

image

The solution was quite easy, you just need to open this URL http://update.microsoft.com/microsoftupdate

image

Check the agreement checkbox and youre done.

image

18 March 2014

Recover free space on a full “System Reserved” partition in Windows Server

One of my servers was reported low free space on “System Reserved” partition. Never seen before such a problem.

When you install Windows and use whole disk for installation, it still does two partitions:

  1. “System Reserved”, without drive letter, few hundred MB in size
  2. C: drive with the rest of the space, several GB in size

I found out after assigning drive letter to the small partition, that most of the space was wasted by “system volume information” folder. This lead me to try “vssadmin list shadows” command to see all VSS snapshots. And indeed there were snapshots present:

image

So I tried to get rid of them by using command “vssadmin delete shadows /for=c:”, but it failed.

image

For that purpose I found utility named diskshadow. I listed all shadows with command “list shadows all” and deleted them with the command “delete shadows all

image

19 February 2014

NIC missing after migrating linux based Hyper-V VM

You might notice, that after moving VHD file to another location and recreating the virtual machine, you don’t have a valid NIC shown in ifconfig output:

image

The solution is to remove /etc/udev/rules.d/70-persistent-net.rules file. After reboot you will have the NIC back:

image

31 January 2014

“VMM cannot find VirtualHardDisk object” when refreshing a virtual machine in Virtual Machine Manager 2012

You might get an error when refreshing a virtual machine on VMM:

Error (801)
VMM cannot find VirtualHardDisk object 3ce58e1c-bfff-421d-8155-b06fb2fb4ea5.

Recommended Action
Ensure the library object is valid, and then try the operation again.

image

To resolve this, use the following SQL command against your VMM database:

delete from dbo.tbl_WLC_VDrive where VHDId='3ce58e1c-bfff-421d-8155-b06fb2fb4ea5'

image

The ID is the same in error message and in SQL command.

Of course you should have backup of your VMM database and stop VMM service before the command and start VMM service after the command.

Updated 19.04.2017:

Today I found out for one vm, that this command would work also if above doesnt help

delete from dbo.tbl_WLC_VDrive where Name='virtualservername'

but first try to find, whether you delete the right one or not by changing “delete” to “select *”

select * from dbo.tbl_WLC_VDrive where Name='life'

24 January 2014

DPM or VMM server gives Error 21201 about SMBIOSGUID when adding a hyper-v host

Edited on 18.04.2017: The same procedure verified to be working with VMM (Virtual Machine Manager) also. Googled my error message and found my own blog post, what a shame Smile

When adding a hyper-v host to Data Protection Manager Server, you might get the following error:

Error (21201)
Another machine with the same SMBIOSGUID is found.

Recommended Action
An SMBIOS GUID should uniquely identify the machine. Please provide the correct value or contact the machine manufacturer to help update the hardware with correct information.

The problem usually is with the same computer have been managed using the same dpm server, but not correctly removed from dpm.

Help comes with following SQL command:

SELECT a.PhysicalMachineId,b.ComputerName FROM tbl_PMM_PhysicalMachine a left join tbl_ADHC_Host b on a.PhysicalMachineId = b.PhysicalMachineId order by ComputerName

This command finds all computers, that are present in DPM server and shows physical machine ID and computer name. Try to find computers with name not present (NULL). If you have them, then delete those records from tbl_PMM_PhysicalMachine table. Use corresponding physicalmachineID for finding them.

Edit on 26.04.2017 --------------------------------------

The command to delete the NULL entries is:

delete from tbl_PMM_PhysicalMachine where PhysicalMachineId = (SELECT a.PhysicalMachineId FROM tbl_PMM_PhysicalMachine a left join tbl_ADHC_Host b on a.PhysicalMachineId = b.PhysicalMachineId where ComputerName is null)

Edit on 10.06.2022 --------------------------------------

Now let's find all computers SMBIOSGUID with that SQL clause:

SELECT
    h.ComputerName,
    p.SmBiosGuid,
    h.PhysicalMachineId
FROM
    tbl_ADHC_Host AS h,
    tbl_PMM_PhysicalMachine AS p
WHERE
    h.PhysicalMachineId = p.PhysicalMachineId
ORDER BY
    ComputerName

16 January 2014

Get rid of old computer accounts in Active Directory

If your Active Directory has been running for several years and you don’t cleanup old computer accounts, then you might run into Active Directoy Users and Computers (dsa.msc) warning:

image

When you really do have more than 2000 computers in your system, then you don’t need to do anything :) But having only tens or hundreds of computers, then you should clean up your AD, perhaps do it regularly.

Every active computer in domain changes it’s (computer account) password every 30 days. Very old Windows NT4 computers every 7 days. Every computer account in Active Directory has information, when the password was last changed (passwordlastset). Let’s assume, that some users go on vacation and don’t use the computer for a month or so. It means, that when you discover a computer account, with passwordlastset older than 60 days, it’s (almost) safe to delete it.

To get the list of computer accounts, that havent changed use this powershell command:

Get-ADComputer -Filter * -Properties passwordlastset | where {$_.passwordlastset -lt (get-date).adddays(-60)} | select Name,PasswordLastSet | ConvertTo-Csv  -Delimiter `t -NoTypeInformation | clip

image

After that you can paste the info into excel and take a look, what computers will be deleted, when you use the next command.

image

When the list is ok for deletion, then use this command:

Get-ADComputer -Filter * -Properties passwordlastset | where {$_.passwordlastset -lt (get-date).adddays(-60)} | Remove-ADObject –Recursive

You can also use -confirm switch to change behaviour of asking whether to delete. This is useful when using this command on scheduled task.

08 January 2014

How to configure Windows Time service in (virtualized) Active Directory environment

Default behavior in Active Directory environment uses your domain controller with PDC emulator role as the primary source for time information and all other domain member servers and workstations use this time as authoritative.
To get the information about FSMO (Flexible single master operation) roles, type:
netdom query fsmo
image
If some of your domain controllers are virtualized, then your clock will soon be left behind. This happens because hyper-v host is obtaining time from primary source (virtualized domain controller) and after the clock on hyper-v host is set, then the same time will be set also on virtualized domain controller itself, creating a loop. During this loop, clock will shift bit by bit and left behind (a minute per week or so).
To overcome this situation, you need to disable hyper-v clock synchronization on all virtual domain controllers:
image
After that you should correct the time on PDC role owned domain controller. You should do this by using external time source. I suggest following commands:
w32tm /config /syncfromflags:manual /manualpeerlist:"ntp.data.ee"
w32tm /config /update

You can replace ntp.data.ee with some other time server on internet. To force the update you could use this command:
w32tm /resync
To show the configuration use this command:
w32tm /query /configuration
To reset messed up w32tm configuration, use following commands:
net stop w32time
w32tm /unregister
w32tm /register
net start w32time

This nice powershell script shows you time information on all domain servers:
$servers = Get-ADComputer -LDAPFilter "(operatingsystem=*server*)"
$servers | foreach {$server=$_.name ; net time \\$server} | clip

First line gets information about AD computers and selects only computers with server operating system. Second line uses net time command to get information for each server and places the result in clipboard, so you can paste it to excel, notepad etc.
Edit 27.04.2016 -------------------------------------------
Today, reconfiguring the situation, I found out, that the easiest thing to do is to use those 2 commands in PDC role owner:
w32tm /config /manualpeerlist:"pool.ntp.org" /syncfromflags:manual /reliable:yes /update
w32tm /resync


Edit 04.12.2018 --------------------------------------------
To see, which domain controller has wrong time in your environment:
$servers = Get-ADDomainController -Filter *
$servers | foreach {$server=$_.name ; net time \\$server | findstr Current}