Background: Trying to get a script that will pull members from a group and list their Full Name, Username and PC. Computer Description is set as user’s Full Name. Display Name of AD User is set to “Surname, FirstName”, which is why I need to pull down givenname and surname and then stitch it together…
$groupmems =get-ADGroupMember -Identity <GroupName> | Select-Object -Property Name $alldesktops = <Some OU searches with computers> $namedetail = $groupmems | % ($_) { Get-ADUser $_.Name -Properties * | select givenname, surname, samaccountname} $names = $namedetail | % ($_) {$_.givenname + " " + $_.surname}; #$login=$_.samaccountname $usernames = $namedetail | % ($_) {$_.Samaccountname} $finallist = @() foreach ($desktop in $alldesktops) { :outer foreach ($line in $usernames) { :inner foreach ($lines in $names) { if ($desktop.description -match $lines) { if ($name.Length -gt 2) { $object = New-Object Object $object | Add-Member NoteProperty Computer $desktop.name $object | Add-Member NoteProperty Username $line $object | Add-Member NoteProperty FullName $lines $finallist += $object break inner } break outer } } } } $finallist | Sort-Object User
The issue is that I can’t get the breaks right to give me the info I need. It either lists every numerous times or I get the right username but PC name is incorrect, etc.
Code has been sanitized but should make sense in the grand scheme of things. I’m sure this could be done more simpler/elegantly too.
submitted by /u/Scrltvx
[link] [comments]
The post List Full Name, Username and Assigned Machine from Security OU appeared first on How to Code .NET.