Need help with AD query and scripting

Welcome Forums General PowerShell Q&A Need help with AD query and scripting

Viewing 2 reply threads
  • Author
    Posts
    • #265523
      Participant
      Topics: 2
      Replies: 1
      Points: 13
      Rank: Member

      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!

    • #265550
      Participant
      Topics: 0
      Replies: 6
      Points: 31
      Rank: Member

      Hi,

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

    • #265553
      Participant
      Topics: 2
      Replies: 1
      Points: 13
      Rank: Member

      Hi,

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

      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.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.