Get-WMIObject Invalid query querying a list a servers
<p>So I'm trying to run a powershell query against a list of servers in an OU in ADUC. Here's the code:</p>

<pre><code>$Serverlist = Get-ADComputer -Filter * -SearchBase ("OU=Member Servers, OU=KDHR, OU=RC South, DC=afghan, DC=swa, DC=ds, DC=army, DC=mil") | Select-Object -ExpandProperty Name

foreach ($Server in $Serverlist) {
$Server
$LastBootUpTime = Get-WmiObject Win32_OperatingSystem $Server | Select -ExpandProperty LastBootUpTime

Write-Host "$LastBootUpTime"
</code></pre>

<p>}
And this is the output I'm getting:</p>

<pre><code>ServerName                                                                                                                                     
Get-WmiObject : Invalid query "select ServerName from Win32_OperatingSystem"
At C:\Users\Me\Desktop\LastReboot.ps1:6 char:19
+ $LastBootUpTime = Get-WmiObject Win32_OperatingSystem $Server | Select -Exp Last ...
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
</code></pre>

<p>It looks like it is trying to pass "Name=SameServerName" into my Get-WMIObject cmdlet, as opposed to just "SameServerName". I output the server name ahead of time just to see what $Server is holding and it seems to come out right, but when it goes in the cmdlet, it seems to add the "Name=" in there. Any idea why?</p>

<p>EDIT: I just realized that I left out the parameter "-ComputerName" in my GetWmiObject cmdlet. So now that line looks like this:</p>

<pre><code>$LastBootUpTime = Get-WmiObject Win32_OperatingSystem -ComputerName $Server | Select -ExpandProperty LastBootUpTime
</code></pre>

<p>It's working now, which is weird because before, I was getting an "RPC is unavailable" error.</p>