We have recently added VDI to our arsenal. I need to modify our build scripts to modify these. I swore this was working, and now it is not, but here is what is happening. I sure could use some assistance.
VDI are created and automatically put on the Domain in the ComputersOU, where physical PC's and laptops are not. I used
Get-WMIObject win32_computersystem.pcsystemtype and Get-WMIObject win32_computersystem.model to determine if the equipment being built is a physical laptop or VDI. If it is a CDI, I have it run this command with the goal to move it from the ComputersOU to the ComputersWB- VDI OU:
## Determine if PC is a VDI based on Model If ($model -like "VMware Virtual Platform") { ## Move PC from ComputersOU to ComputersWB\VDI OU based on Model $AD = [ADSI]'' # Setup the search criteria $ADSearch = New-Object System.DirectoryServices.DirectorySearcher $ADSearch.SearchRoot = $AD $ADSearch.Filter = "(objectclass=computer)" $Results = $ADSearch.FindAll() | Where-Object {$_.properties.item("cn") -like $CN} # Get the DN of the object $ComputerDN = $Results.Properties.Item("DistinguishedName") # Connect to the computer object $Object = [ADSI]"LDAP://$ComputerDN" # Specify the target OU $TargetOU = "OU=VDI,OU=ComputersWB,DC=BLAIRNET,DC=NET" $TargetOU="LDAP://$targetOU" # Move the object to the target OU $Object.psbase.MoveTo($TargetOU) }
I swore this was working. I really did, but when I ran it again on a new VDI, it fails miserably. Doing some troubleshooting, it fails almost immediately and i don't know why.
When I run the line $AD = [ADSI]'', I get the following error:
format-default : The following exception occurred while retrieving member "distinguishedName": "The specified domain either does not exist or could not be
contacted.
"
+ CategoryInfo : NotSpecified: (:) [format-default], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Commands.FormatDefaultCommand
Looking for some guidance on how to move this VDI automatically to another OU using ADSI commands or to figure out why I am getting this error. Maybe I was logged in as myself when it worked, but I swore it worked as it was supposed to logging in a a local user - not a domain user.
Any help or thoughts appreciated.
Matt
Matt Dillon