Hi Guys,
Hope all is great, I need your assistance with a query I am trying to do and unfortunately it doesn't work.
I have a list of Windows machines that I query from SCCM and get it to my varible (see attach below), the result shows "Windows Computers Name", " "AD Name", "Type of machines"
Then I go over for each VM and ask for tags + custom attribute, IP and VMNAME, the thing is that if I run this on certain vcenter all great and works get all results as wanted
But, I must run it parallel for all my 4 vcenters becasue those WIndows machines located on different 4 vcetners, the main purpose is the get "Pending Reboot machines" from SCCM list and then get their tags and CA.
The problem is that i get results which are great but no for all VM's some VM are not returning tags and custom attributes even that they have it, even that again if I run it direct query to the VM i got results.
In SCCM query I got Windows pending reboot machines some of them are physical so I am in "Else" if Windows machine name does not appear on Vcenter just type Windows name and type (the type is VM or Physical server that SCCM provides)
This is my code:
$rrr

$poweredOnWindowsVMs = Get-VM -Server "vc1.vmware","vc2.vmware","vc3.vmware","vc4.vmware" | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.Guestid -like "*windows*"}
foreach ($sccm in $rrr) {
if ($poweredOnWindowsVMs.Name -contains $sccm.Name) {
$Owner = (Get-VM -Name $sccm.Name).CustomFields | Where-Object {$_.Key -eq "Owner Email:"} | Select-Object -ExpandProperty Value
$VMIP = (Get-VM -Name $sccm.Name).Guest.IPAddress | Where-Object {$_ -notlike "*:*"}
$Department = Get-VM -Name $sccm.Name | Get-TagAssignment | Where-Object {$_.Tag -like "*department*"} | Select-Object -ExpandProperty Tag | Select-Object -ExpandProperty Name
$VMname = (Get-VM -Name $sccm.Name).Name
[pscustomobject]@{
"VMOwner" = $Owner
"VMName" = $VMname
"IP" = $VMIP -join ';'
"Type" = $sccm.Type
"Department" = $Department
"ADName" = $sccm.ADname
}
} else {
[pscustomobject]@{
"ADName" = $sccm.adname
"Type" = $sccm.type
}
}
}
)