After experiencing a lot of down time, We decided to move this site to
CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.
Powershell Script Question - Beginner
|
Author |
Message
|
aherfindahl
-
Total Posts
:
1
- Scores: 0
-
Reward points
:
0
- Joined: 3/9/2010
-
Status: offline
|
Powershell Script Question - Beginner
Tuesday, March 09, 2010 10:17 AM
( permalink)
How would I go about creating a Powershell script that says: if a user is a member of one AD group and their machine is in another AD group run this bat file?
|
|
|
|
ginolard
-
Total Posts
:
1347
- Scores: 23
-
Reward points
:
0
- Joined: 8/11/2005
-
Status: offline
|
Re:Powershell Script Question - Beginner
Wednesday, March 10, 2010 12:38 AM
( permalink)
Well, firstly, I would recommend getting the Quest AD Cmdlets. They make scripting for AD a whole heap easier. This is untested as our computers aren't members of any groups but it should work.
$UserGroups = (Get-QADUser <username>).memberof
$CompGroups = (Get-QADComputer <computername>).memberof
If ($UserGroups -Contains "X" -And $CompGroups -contains "Y") {
Invoke-Expression "batfile"
}
And if you really MUST have it as a one-liner
If ((Get-QADUser <username>).memberof -Contains "X" -And (Get-QADComputer <computername>).memberof -contains "Y") {Invoke-Expression "batfile"}
<message edited by ginolard on Wednesday, March 10, 2010 12:39 AM>
|
|
|
|
ebgreen
-
Total Posts
:
8088
- Scores: 95
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Powershell Script Question - Beginner
Wednesday, March 10, 2010 3:34 AM
( permalink)
The QAD cmdlets are handy. Here is how you would do it without them: $domain = [adsi]'' $searcher = New-Object System.DirectoryServices.DirectorySearcher $searcher.SearchRoot = $domain $searcher.filter = "(&(ObjectClass=User)(name=<USERNAME>))" $UserGroups = $searcher.FindOne().properties.memberof $searcher.filter = "(&(ObjectClass=Computer)(name=<COMPUTERNAME>))" $CompGroups = ($searcher.FindOne().properties.memberof If ($UserGroups -Contains "X" -And $CompGroups -contains "Y") { Invoke-Expression "batfile" }
|
|
|
|
sdm44990
-
Total Posts
:
18
- Scores: 0
-
Reward points
:
0
- Joined: 1/26/2007
-
Status: offline
|
Re:Powershell Script Question - Beginner
Tuesday, March 23, 2010 10:59 PM
( permalink)
Get an R2 box for mgmt, and install AD web service on your DCs. New R2 cmdlets have all sorts of great AD stuff, and group policy cmdlets as well.
|
|
|
|
Online Bookmarks Sharing: