Asked by:
Report back Servername and Version

Question
-
i exported servers names from AD to servers.txt - i want to report servername, version,
My script keeps reporting back my workstation and my Version number. Why does it do that? what is the syntax to report ServerName and Version?
PS C:\> get-content c:\Temp\servers.txt | foreach {Get-WmiObject Win32_OperatingSystem} | select PSComputerName, Version
PSComputerName Version
-------------- -------
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393
SSMLXP600 10.0.14393Friday, May 19, 2017 1:34 PM
All replies
-
See help for Get-WMIObject cmdlet.. you need to use parameter to specify remote computer name which you're not using. so, for each loop iteration, it is running on local system only, giving you same results
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/get-wmiobject?f=255&MSPPError=-2147217396
cheers..uc
Friday, May 19, 2017 2:25 PM -
Try below code :
Get-Content c:\temp\test.txt | foreach{Get-WmiObject -cn $_ win32_operatingsystem | select csname,Version}
Please mark as answered if it helps.
- Proposed as answer by Lokesh_Agarwal Friday, May 19, 2017 3:06 PM
Friday, May 19, 2017 3:06 PM -
Tried the code above four servers reported back then the red screen of errors
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:39
+ ... \servers | foreach{Get-WmiObject -cn $_ win32_operatingsystem | selec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommandWhat can I do to rectify the RPC Server is unavailable?
Friday, May 19, 2017 3:57 PM -
Hi,
>>What can I do to rectify the RPC Server is unavailable?
RPC server is unavailable also contains many reasons.
First of all, you need to consider the firewall settings for RPC related ports, you could open firewall find out the RPC related rules to check.
Second, if you wanted to bypass this error you could do like this:
$servers = Get-Content c:\temp\test.txt foreach($ser in $servers) { if(Test-Connection -ComputerName $ser) { Get-WmiObject -cn $_ win32_operatingsystem | select csname,Version }else{ Write-Host "connect to remote server failed!" } } OR: Get-Content c:\temp\test.txt | Invoke-Command -ComputerName $_.servername -ScriptBlock{ Get-WmiObject win32_operatingsystem | select csname,Version}` -ErrorAction SilentlyContinue -Credential contoso\admin
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- Proposed as answer by Hello_2018 Monday, June 5, 2017 3:04 AM
Monday, May 22, 2017 6:33 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
AndyPlease remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Monday, June 5, 2017 3:04 AM