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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mhamerAuthor Commented:
Great thank you will give that a go
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.