I'm working on a PowerShell script that creates a CSV file with Active Directory Organizational Unit, its Groups and its Members.
So far so good, I got the .csv
Now I want to include another column in the CSV that indicates whether the Member name contains a specific string text.
For example, member name:
Barack Obama (admin) Donald Trump (user) Richard Nixon Now I'd like to have another column that indicates "True" for all administrators based on the string piece "(admin)". If it contains "(admin)" it will say True. Else, it will say False.
This is how far I got but I'm a total newbie with PowerShell.
$OU = 'OU=EMEA,OU=Admins,OU=XXXXX,OU=Admin,DC=emea,DC=xxxx,DC=xxxx' $Path = 'I:\Users\xxxx.xxx\Desktop\output.csv' $Groups = Get-ADGroup -Filter * -SearchBase $OU $Data = foreach ($Group in $Groups) { Get-ADGroupMember -Identity $Group -Recursive | Select-Object @{Name='Organizational Unit';Expression={$OU}}, @{Name='Group';Expression={$Group.Name}}, @{Name='Member';Expression={$_.Name}} --- // now I need some IF statement I guess \\ --- If ( $_.Name -contains '(admin)') { Write-Host "True" } Else { write-host "False" } } }