Skip to content

Instantly share code, notes, and snippets.

in this script, I am trying to Determine SQL Server hosted servers if it's VM or Physical Remotely using Powershell
$Servers = Read-Host "Please Add Text File Path that Contain all servers IP "
$Target = Get-Content -Path $Servers
$hosted = Invoke-Command -ComputerName $Target -ScriptBlock {Get-wmiobject win32_computersystem |
Where-Object model -EQ 'Virtual Machine'} -Credential (Get-Credential)
$result=@()
if ($hosted)
{
$result+=New-Object -TypeName PSObject -Property ([ordered]@{
'Computer IP'=$hosted.PSComputerName;
'Hosted On'=$hosted.Model;
})
}
else
{
$result+=New-Object -TypeName PSObject -Property ([ordered]@{
'Computer IP'=$hosted.PSComputerName;
'Hosted On'='Physical Server';
})
}
Write-Output $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment