Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell test path - active roles

Posted on 2014-10-02
11
Medium Priority
?
199 Views
Last Modified: 2014-10-15
Hi guys,

When i run this command:

(Get-QADUser sst446).MemberOf

this use is part of server groups, now i need to know if this user is part of a group with the character fsr-prs, so i tried this and it fails:

(Get-QADUser yew357).MemberOf | % { if (*fsr-prs*){echo "pass!" } }

after i fix this stage, i need to put this group in variable. but lets fix this step first. please can someone help me.
0
Comment
Question by:Kay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40357423
(Get-QADUser yew357).MemberOf | % { if  ($_ -like "*fsr-prs*"){write-host "pass!" } }

Open in new window


Based on the output from get-qaduser we run a like match against it.
0
 

Author Comment

by:Kay
ID: 40357455
i;ve just got it to work!!!

(Get-QADUser yew357).MemberOf | % { if ($_  -like "*fsr-prs*"){echo "$_" } }

the result of $_ are:

 cn=dl-fsr-prs-eaf-pol....,ou=....., ,ou=...
 cn=dl-fsr-prs-eaf-df....,ou=....., ,ou=...
 cn=dl-fsr-prs-eaf-ois....,ou=....., ,ou=...

the only bit i need fsr-prs-eaf and i need this in a variable. then i need to add this to antother variable with the text \\wm.ws.qre.ac.uk

and i want this to equal to  \\wm.ws.qre.ac.uk\fsr-prs-eaf\users\yew357

i then need to do a test-path \\wm.ws.qre.ac.uk\fsr-prs-eaf\users\yew357

please help!
0
 
LVL 22

Expert Comment

by:mcsween
ID: 40357459
This will write all groups that contain the string "frs-prs" that User1 is a member of.

get-qaduser User1| Get-QADMemberOf | ForEach-Object {if ($_.name.contains("frs-prs") -eq $true) {write-host $_.name }}

Open in new window

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 29

Expert Comment

by:becraig
ID: 40357480
(Get-QADUser yew357).MemberOf | select -expand name  | % { if  ($_ -like "*fsr-prs*"){write-host "pass!" } }

Open in new window


So I do not have a test, but you can probably  do the above or make a split.

(Get-QADUser yew357).MemberOf | % { if  ($_ -like "*fsr-prs*"){$gval = $_.split(",") -replace "cn=","";write-host "pass!" } }

Open in new window

0
 

Author Comment

by:Kay
ID: 40359094
after this completes when i do a $gval[0] on powershell i get:

DL-FSR-PRS-EST-R

the only test i need is the prs-est

how do i split this again,

i then need to convert prs-est to prs\est and add \\wm.qw.ac.uk\fac & usr at the end, which would the equal to \\wm.qw.ac.uk\fac\prs\est\usr

please help!
0
 

Author Comment

by:Kay
ID: 40359125
if i do $gval[0].split("-")[1]

it gives me fsr,

i need the prs too! please help if put a 2 also therefore $gval[0].split("-")[1][2]

it gives me
just r
0
 

Author Comment

by:Kay
ID: 40359129
got it! its $gval[0].split("-")[1..3]

gives me

fsr
prs
est

now how do i put them in a \fsr\prs\est
0
 

Author Comment

by:Kay
ID: 40359137
i've got this far:

(Get-QADUser yew357).MemberOf | % { if  ($_ -like "*fsr-prs*"){$gval = $_.split(",") -replace "cn=","" }

$s=$gval[0].split("-")[1..3]

}
0
 

Author Comment

by:Kay
ID: 40359147
if writ this however only the group name appears when user is not in group instead i need the script to say that user aaw558 is not in group

(Get-QADUser aaw558).MemberOf | % { if  ($_ -like "*fsr-prs*"){$gval = $_.split(",") -replace "cn=","" }

else {echo "User $_ is not in a group"}

$s=$gval[0].split("-")[1..3]

}


please help!
0
 

Author Comment

by:Kay
ID: 40359158
$s values:

fsr
prs
est

now how do i put them in a \fsr\prs\est

?
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 40359798
Sorry you need to simply add join.
 $s  = ($s.split("-")[1..3] -join"-") -replace "-", "\"

Open in new window

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Let's recap what we learned from yesterday's Skyport Systems webinar.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question