none
Run process on OU but include an exclusion group? RRS feed

  • Question

  • Hi All,

    I have a Powershell script that queries a specified OU for computer names and then runs a batch script on each computer (the script kicks off a reboot but prompts the user to cancel if they'd like). I would like to know how I can specify an exclusion group in this script. Say I have a group in Active Directory called WeekendRebootExclusion with some computers as members. How would I exclude these machines from the process in the script?

    Import-Module ActiveDirectory

    Get-ADComputer -SearchBase 'OU=Reboot Test,OU=Workstations,OU=Test,DC=abc,DC=xyz,DC=com' -Filter '*' | Select -Exp Name |
     ForEach-Object{
            Start-Process "WeekendReboot.bat" $_
        }

    Wednesday, March 14, 2018 10:58 PM

Answers

  • jrv: You're useless, best not to answer.

    I ended up going this route for anyone that is interested:

    Import-Module ActiveDirectory

    $Exclude = Get-ADGroupMember RES_RebootExclusionTest | Select -Exp Name

    Get-ADComputer -SearchBase 'OU=Reboot Test,OU=Workstations,OU=Test,DC=abc,DC=xyz,DC=com' -Filter '*' | Select -Exp Name |
     ForEach-Object{
      if($Exclude -notcontains $_){
            Start-Process "WeekendReboot.bat" $_
            }
        }


    • Edited by iTsLiKeAnEgG Thursday, March 15, 2018 3:20 PM
    • Marked as answer by iTsLiKeAnEgG Thursday, March 15, 2018 3:20 PM
    Thursday, March 15, 2018 3:20 PM

All replies

  • help where-object -online

    It would be best if you learned PowerShell first.

    Script Center

    Learn PowerShell  


    \_(ツ)_/

    Wednesday, March 14, 2018 11:49 PM
  • jrv: You're useless, best not to answer.

    I ended up going this route for anyone that is interested:

    Import-Module ActiveDirectory

    $Exclude = Get-ADGroupMember RES_RebootExclusionTest | Select -Exp Name

    Get-ADComputer -SearchBase 'OU=Reboot Test,OU=Workstations,OU=Test,DC=abc,DC=xyz,DC=com' -Filter '*' | Select -Exp Name |
     ForEach-Object{
      if($Exclude -notcontains $_){
            Start-Process "WeekendReboot.bat" $_
            }
        }


    • Edited by iTsLiKeAnEgG Thursday, March 15, 2018 3:20 PM
    • Marked as answer by iTsLiKeAnEgG Thursday, March 15, 2018 3:20 PM
    Thursday, March 15, 2018 3:20 PM
  • Yes you can get others to do your thinking but learning is the more professional approach to problem solving for technicians.

    "Give a guy an answer and he will not be hungry today.  Give a tech a way to find an answer and hw will never be hungry again."

    Glad to here you are not hungry today. 


    \_(ツ)_/


    • Edited by jrv Thursday, March 15, 2018 5:26 PM
    Thursday, March 15, 2018 5:24 PM
  • "jrv: You're useless, best not to answer." Couldn't agree more.  Apparently everyone should master Powershell before asking a question here.  
    Thursday, March 15, 2018 6:07 PM
  • Everyone should learn to use a search engine and to se help. 

    The question was about how to us "Where-Object"

    Get-ADComputer -SearchBase 'OU=Reboot Test,OU=Workstations,OU=Test,DC=abc,DC=xyz,DC=com' -Filter * |
        Where-Object{$excluded -notcontains $_.Name} |
        ForEach-Object{ Start-Process WeekendReboot.bat $_.Name }
    Scheduled reboots are unnecessary if proper maintenance practices are followed.


    \_(ツ)_/


    • Edited by jrv Thursday, March 15, 2018 6:26 PM
    Thursday, March 15, 2018 6:24 PM
  • not going to lie this is some spicy stuff right meow.
    Thursday, March 15, 2018 6:35 PM