This Powershell script can help identify whether servers in Active Directory are virtual or physical.
Create a new Powershell script file named Get-Physical.ps1 with below contents.
$serverList = Read-Host -Prompt "Specify OU Distinguished name: (eg. OU=Normal Services - 2008 Servers,OU=Servers,DC=CONTOSO,DC=LOCAL";
#Generates servers.txt file from above input query, searching and generating list of servers within OU.
Get-ADComputer -filter * -SearchScope Subtree -SearchBase $serverList | select name | Export-CSV servers.txt
$servers = Get-Content 'Servers.txt' | Foreach-Object {$_ -replace "`"", ""};
foreach($server in $servers)
{
try
{
$compsys=get-wmiobject -computer $server win32_computersystem -ErrorAction SilentlyContinue
if($compsys.model.toupper().contains("VIRTUAL"))
{
write-output "$server is Virtual"
}
Else
{
write-output "$server is Physical"
}
}
catch
{
write-output "$server is not Windows OS or insufficient access"
}
}
