filter online workstations and make pssession

Welcome Forums General PowerShell Q&A filter online workstations and make pssession

Viewing 1 reply thread
  • Author
    • #233227
      Topics: 20
      Replies: 11
      Points: 205
      Rank: Participant

      Get-ADComputer -Filter * -SearchBase “OU=Systems,OU=Alex,DC=com,DC=cn
      I can filter out all computer in the OU of Systems,

      Get-ADComputer -Filter * -SearchBase “OU=Systems,OU=Alex,DC=com,DC=cn” | foreach {Test-WSMan -ComputerName $_.DNSHostName}
      Then I know which computer is online.

      Then I want to use new-pssession to create a session for every online computer only.
      but how to do that in the pile after I test the computer. I want to complete my request in one line by using pile.
      I also want to add the DNSHostName to an additional text file for the on line computer by using > textfile.txt after test-wsman
      any good idea ?

      • This topic was modified 1 month, 1 week ago by tlsalex27.
    • #233239
      Topics: 5
      Replies: 2384
      Points: 6,066
      Helping Hand
      Rank: Community MVP

      To test a connection you would normally use Test-Connection. 😉
      With that you can use an if statement to check the availability of the remote computers and when they are online you can use New-PSSession in your Foreach-Object loop.

      BTW:When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.