13 April 2018

PowerShell : Find user exist in AD -GROUP

Some times we do need to find users exist in AD group we assign any tickets and perform any activity
here is a sudo code i created in powershell to help you.

Code Step 1 Should be part of input


$cmdOutput = net group YOURADGROUPNAME /domain ;
$var = "USERNAME";



Code Step 2 : loop users and check for user



function finduser() {
for($i = 0; $i -lt $cmdOutput.Count; $i++) {
if($cmdOutput[$i] -eq $var){
$found="T"
write-host "--FOUND-->" $cmdOutput[$i]}
}
if($found -eq "T"){
write-host -ForegroundColor Green "Wow user found " $var}
else {
write-host -ForegroundColor Magenta "SORRY -Scanned records "$cmdOutput.Count " But " $var " not Found"
}
}

finduser



No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: