Need help with AD query and scripting

Hello, I am attempting to pull a list of computers from AD, store them in a variable and run a script that will determine the UAC status of those computers.

Here is what I have so far:

$time = (Get-Date).Adddays(-90)

$vm = (Get-ADComputer -Filter { OperatingSystem -Like ‘Windows Server’-and LastLogonTimeStamp -gt $time } | Where-Object {$_.distinguishedname -notmatch “OU=Domain Controllers”} | Select-Object -ExpandProperty Name)

$cred = get-credential

Invoke-Command -VMName $vm -ScriptBlock {REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA} -Credential $cred

It looks like the query works just fine. I get a list of servers that are not domain controllers and omit inactive servers. The issue is when I run the last line an error returns: “The input VMName xxxxxx does not resolve to a single virtual machine.”

Any help is greatly appreciated!

Hi,

As a quick suggestion, does it work if you use -ComputerName instead of -VMName ?

[quote quote=265550]Hi,

As a quick suggestion, does it work if you use -ComputerName instead of -VMName ?

[/quote]

Wow, that worked! Only problem now is my output is merely the registry line for each machine but no way to tell line belongs to which machine. How can I add the computer name to this output? Sorry, I am very new to PS.