I have a script Get-QadGroup -SearchRoot 'test.com/Master/Groups/Groups - Secure/Soft' | Sort Name | Select Name, Description, Notes, Managedby
The problem I have is I am getting the DN for Managed by. How do I make it so it just displays the name of the person who manages the group "John Doe" and not (CN= John Doe ,OU=FL,OU=Users,DC=test,DC=com)
Also I would like to export this to a csv file in a table format.
Thank you so much
There's nothing built-in to do this. The best-performance way would be to use a regular expression to extract the name. You could also play with the string-handling functions of the String object. Like, find the location of the first comma, then grab the fourth character through the position just before the first comma.
Alternately, you could use that DN to retrieve the actual user object (using Get-QADUser, probably). That object will have a Name property that's just the name (or FullName, or whatever you're after).
Also, there's no such thing as "CSV file in a table format." It's either CSV, or its a textual table. If you want to export to CSV, pipe your output to Export-CSV. If you want a text table, pipe to Format-Table.
Quick and dirty example...
function Split-DN {
param([string]$dn)
$pieces = $dn -split ","
$output = @{}
foreach ($piece in $pieces) {
$bits = $piece -split "="
$counter = 1
while ($output.contains($bits[0])) {
$bits[0] += $counter
$counter++
}
$output.add($bits[0],$bits[1])
$output
$groups = Get-QadGroup -SearchRoot 'test.com/Master/Groups/Groups - Secure/Soft' | Sort Name | Select Name, Description, Notes, Managedby,@{label='cn';expression={(split-dn $_.name).cn}}
I have no idea what just happened. I am sorry, maybe I should have specified that I am new to programming and powershell? I dont want to bother you but giving me an example using something practical would help? like using the example I used? So sorry to bug you with such simple stuff (for you)
Yes, that would have been good to know. I edited my example. You have to understand, though, that I can't *test* this - I'm not in your environment. So if you're not getting exactly what you want, you'll need to teach yourself a bit about what's going on, and tweak from there.