Powershell Ifmemeber type command?

Hi im looking to create a powershell script  that checks group membership and does various things based on outcome

ifmember of group 1  then do job1
ifmember of group 1 then do job 2
if member of group 3 then job 3
carry on with script

type if thing, imm sure you get the idea :-)

i can do this with ifmember just looking for powershell equivilant.
mhamerAsked:
Who is Participating?
 
Chris DentPowerShell DeveloperCommented:

So it'll be running in the context of a user logging on to a system?

I can be done, but you won't get a quick "ifmember" type command simply because there isn't one.

That said, we can get reasonably close. Perhaps like this, it will return a Boolean value. This example tests for membership of Domain Users:

([ADSI]"WinNT://$($Env:UserDnsDomain)/Domain Users").IsMember("WinNT://$($Env:UserDnsDomain)/$($Env:UserName)")

Note that the group name you use must be the Pre-Windows 2000 Group Name.

Chris
0
 
Chris DentPowerShell DeveloperCommented:

What context are you running this in?

PS doesn't have an IfMember equivalent. You can write one, or you can use a number of different methods exposed by the .NET framework. Which is appropriate depends on context.

Chris
0
 
mhamerAuthor Commented:
will be a deployment by sccm

would have like to do one PS script but i guess  three seperate packages would do.

so the PS script will be called by sccm install.cmd
0
 
mhamerAuthor Commented:
not sure if this helps but..

the package runs as a (svc account )

a seperate package ruiing as a user process will then copy the files to profile path (as administrater)
0
 
mhamerAuthor Commented:
Great thank you will give that a go
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.