VMware Cloud Community
AaronJ9201
Contributor
Contributor
Jump to solution

comparing some objects... help with variables and formatting

I want to delete computer accounts in an OU that do not exist in a vmware folder....

Step 1. Compare.

$ad = Get-QADComputer -SearchRoot 'domain.lan/Test-NoGPO'
$vmware= Get-VM -Location VDI_RemoteAccess
Write-Host "AD" $ad
Write-Host "VMWARE" $vmware
Compare-Object  $ad $vmware

That gives me this output:

AD DOMAIN\DSTASA1$ DOMAIN\SXCH100$ DOMAIN\SKFB111$ DOMAIN\FAKEPC$

VMWARE vstaq16 vstaq18

InputObject                                                               SideIndicator                                                          

-----------                                                               -------------                                                          

vstaq16                                                                   =>                                                                     

vstaq18                                                                   =>                                                                     

DOMAIN\DSTASA1$                                                          <=                                                                     

DOMAIN\SXCH100$                                                          <=                                                                     

DOMAIN\SKFB111$                                                          <=                                                                     

DOMAIN\FAKEPC$                                                           <=   

I need the output of the first 2 commands to be the same... preferably just the "name" of the pc. On the compare-object line I tried using $ad.Name and $vmware.Name but that errors and says that it's null when the script runs...

How can I sanitize these lists and end up with a list of machines that aren't in both places? (to later be deleted with some other commands, not relevant here)

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You were halfway there when you tried with the Name property.

But you have to store all computernames in 1 array and all the VMnames in another array.

Then you can compare the 2 arrays.

Something like this

$ad = Get-QADComputer -SearchRoot 'domain.lan/Test-NoGPO' | %{$_.Name}
$vmware= Get-VM -Location VDI_RemoteAccess | %{$_.Name}

Compare-Object $ad $vmware


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You were halfway there when you tried with the Name property.

But you have to store all computernames in 1 array and all the VMnames in another array.

Then you can compare the 2 arrays.

Something like this

$ad = Get-QADComputer -SearchRoot 'domain.lan/Test-NoGPO' | %{$_.Name}
$vmware= Get-VM -Location VDI_RemoteAccess | %{$_.Name}

Compare-Object $ad $vmware


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
AaronJ9201
Contributor
Contributor
Jump to solution

You're the man. I don't really understand why my first attempt didn't work, but all is well. Now to refine my compare command and start deleting accounts.

0 Kudos