I need to get some local server name comparison between the AD Computer Object and the local computer name using Powershell script.
The below script is what I have come up with but somehow does not show the result of the 'Local Computer Name' column for Windows Server 2003.
Get-ADComputer -Filter { (operatingSystem -like '*2003*') -or (operatingSystem -like '*2008*') } |
Where-Object { Test-Connection -ComputerName $_.Name -Count 1 -Quiet } |
Select-Object -Property `
Name,
@{ N = 'Invoke-Command result'; E = { Invoke-Command -ComputerName $_.Name -Scriptblock { HOSTNAME } } },
@{ N = 'PsExec (32bit) result'; E = { PsExec.exe "\\$($_.Name)" /accepteula cmd /c "HOSTNAME" 2>&1} },
@{ N = 'PsExec (64bit) result'; E = { PsExec64.exe "\\$($_.Name)" /accepteula cmd /c "HOSTNAME" 2>&1} } |
Sort-Object Name |
Out-GridView
I have updated the code to the above as suggested from some of the experts below. However, the result is now showing like: