andyferris
IS-IT--Management
I have some code:
Get-ADGroupmember -Identity Servers|Select-Object -ExpandProperty name|Sort-Object
Which returns a simple list of members of the "Servers" group.
A foreach loop then does other stuff with that list (finds stopped services and restarts them)
What I would like to do is to give myself the option of sometimes excluding some servers from that list.
I know I could put in a where-object{$_.name -ne 'server1' -and....... } etc, but the list changes each time and I would like to automate this with a scheduled task so to make it easier I wonder if I could use some kind of variable. something along the lines of:
$excludedservers="server1","server2"
Get-ADGroupmember -Identity Servers|Where-Object{$_.name -ne $excludedservers}|Select-Object -ExpandProperty name|Sort-Object
This doesn't work though, it still produces the full list.
Can anyone point me in the right direction? maybe a foreach is needed? I cant see how to do it.
Thanks
Get-ADGroupmember -Identity Servers|Select-Object -ExpandProperty name|Sort-Object
Which returns a simple list of members of the "Servers" group.
A foreach loop then does other stuff with that list (finds stopped services and restarts them)
What I would like to do is to give myself the option of sometimes excluding some servers from that list.
I know I could put in a where-object{$_.name -ne 'server1' -and....... } etc, but the list changes each time and I would like to automate this with a scheduled task so to make it easier I wonder if I could use some kind of variable. something along the lines of:
$excludedservers="server1","server2"
Get-ADGroupmember -Identity Servers|Where-Object{$_.name -ne $excludedservers}|Select-Object -ExpandProperty name|Sort-Object
This doesn't work though, it still produces the full list.
Can anyone point me in the right direction? maybe a foreach is needed? I cant see how to do it.
Thanks