is it possible to get a list of non virtual servers in the domain with get-adcomputer?
If you are logged into a computer that's on the network and running vcli then just doing a net view would work. You can't manage them and run commands for them through the vcli in the same respect as you could a VM, so simply listed machines on the network can be done through the command prompt as you normally could.
Maybe we'd be able to help you better if you replied stating exactly what you are trying to accomplish.
Good Luck!
Afaik none of the AD object properties will tell you if a machine is virtual or not (unless you added some properties yourself to the schema).
I sometimes use a combination of Get-ADComputer and Get-WMIObject to do this filtering.
Something like this
Get-ADComputer -Filter {OperatingSystem -like "*server*"} | `
where {(Get-WmiObject -Class Win32_BIOS).SerialNumber -notlike "VMware*"} | `
Select Name
If you want the virtual servers, just replace -notlike with -like.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i tried that but it seems to bring up a list of both virtual and physical.
You can make a list of VM's with PowerCLI and compare the computers that Get-ADComputer returns with this list, to select only the computers that are not in the list. The next script does this. It assumes that the computernames in Active Directory are the same as the VM names.
$VmList = @() Get-VM | ` ForEach-Object {$VmList += $_.Name} Get-ADComputer -Filter {OperatingSystem -like "*server*"} | ` Where-Object {$VmList -notcontains $_.Name}
I made another version of this script that uses the servername of the guest instead of the VM name. This will give better results if your VM names are different than the guest names. It uses the Guest.HostName property of a VM. This property will be empty if the VMware Tools are not installed. That's why I added a filter to select only the VM's that have this property filled, before I add them to the list of VM's.
$VmList = @() Get-VM | ` Where-Object {$_.Guest.HostName} | ` ForEach-Object {$VmList += $_.Guest.HostName.Split(".")[0]} Get-ADComputer -Filter {OperatingSystem -like "*server*"} | ` Where-Object {$VmList -notcontains $_.Name}
Regards, Robert
Message was edited by: RvdNieuwendijk. Added the filter for servers and added the second script
Perhaps the filtering is not correct.
Does this show you all machines in the domain and is the OperatingSystem property distinguisable from PCs by the presence of the term "server" in that property ?
Get-ADComputer -Filter * -Properties OperatingSystem | Select Name,OperatingSystem
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes this show all machines including desktops. and it does show the Operating system of desktops and servers.
Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} -Properties OperatingSystem | Select Name,Ope
ratingSystem
seems to give the same output. maybe something wrong with the wmi filter?
Not sure what goes wrong here.
Can you try the folllowing with a couple of servers
Get-WmiObject -Class WIN32_BIOS -ComputerName ServerName
and check if you see the SerialNumber property starting with "VMware" only when the <ServerName> machine is a virual box ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes it does. it gives VMware in a virtual box.
for the wmi filter, the machine has to be online to work right?
I tried this and it seems to work.
> Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} -Properties OperatingSystem | where {(Get-Wmi
Object -Class WIN32_BIOS -ComputerName $_.Name).SerialNumber -NotLike "VMware*"} | Select Name,OperatingSystem
however a lot of these errors:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:110
+ Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} -Properties OperatingSystem | where {(Get-WmiObject <<<< -
Class WIN32_BIOS -ComputerName $_.Name).SerialNumber -NotLike "VMware*"} | Select Name,OperatingSystem
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
how do I modify the query to ignore the offline servers?
My mistake, I assumed that the ComputerName parameter would take pipeline input, and it doesn't.
To avoid offline hosts, you can do something like this
Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} -Properties OperatingSystem | `
where {(Get-WmiObject -Class WIN32_PingStatus -filter "address = '$_.Name'").StatusCode -eq 0} | `
where {(Get-WmiObject -Class WIN32_BIOS -ComputerName $_.Name).SerialNumber -NotLike "VMware*"} | `
Select Name,OperatingSystem
The first Where-clause will only pass hosts that reply to a ping and hence are online.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i am getting a blank list. with the second wmi filter
Did you try the WIN32_PingStatus on it's own to validate you get the StatusCode 0 for online hosts ?
Just to make sure, you did escape the variable in the filter with single quotes ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes I added the single quotes in there.