Author Posts

July 26, 2017 at 1:03 pm

Hello!
I got a very easy script

Get-ADUser -SearchBase "OU=users,OU=orgunit,DC=org,DC=local" -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
     -Properties * | Select IDIdentifierType, sAMAccountName, Mail | `
    Export-Csv -Path c:\Users.csv -NoTypeInformation

as a result I got
"IDIdentifierType","sAMAccountName","Mail"
"Microsoft.ActiveDirectory.Management.ADPropertyValueCollection","truhachev_iu","truhachev_iu@mrsks.ru"
How should I modify the script to get
"IDIdentifierType","sAMAccountName","Mail"
"","truhachev_iu","truhachev_iu@mrsks.ru"
?
I would like to create a csv file that is filled in with some default values ("" in this case), but I do not know how to tell powershell use empty values instead of AD properties.
Any ideas?

July 26, 2017 at 1:58 pm

... select @{n="AnySynteticPropertyName"; e={ "Any" + ($valid) + 'scriptblock' } }, AnyRealProperty ...

July 26, 2017 at 2:02 pm

in your case, if you want empty properties, even better 🙂

Get-ADUser -SearchBase "OU=users,OU=orgunit,DC=org,DC=local" -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
     -Properties * | Select * | Select IDIdentifierType, sAMAccountName, Mail | `
    Export-Csv -Path c:\Users.csv -NoTypeInformation

July 26, 2017 at 2:12 pm

за оба варианта спасибо большое!
Первый (с Label и Evaluations )успел сам нагуглить, правда 🙂

August 1, 2017 at 9:29 am

Hello!
In case someone know 🙂
Got a script

$filename = "c:\users" + (Get-Date -Format "yyyy-MM-dd-HH-mm-ss") + ".csv"
$mRecordNumber = $null # or set integer to limit number of lines in the resulting CSV file
$mSearchBase = "OU=Users, OU=orgunit, DC=dc,DC=local"
Get-ADUser  `
            -ResultSetSize $mRecordNumber  `
            -SearchBase $mSearchBase  `
            -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
            -Properties * | `
      Select `
      @{L='Manager'; E={""}}| `
    Export-Csv -Path $filename -NoTypeInformation -Encoding UTF8

and the manager field contains
Manager : CN=ivanov,OU=orgunit,DC=dc, DC=local
string.
Is there a way to get GivenName of that particular user in the run-time?

August 1, 2017 at 9:31 am

smth like

@{L='Manager'; E={Get-ADUser $.Manager -Properties .GivenName }}|

?

August 1, 2017 at 12:31 pm

You can try below given script :

Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | select -expand displayname | Export-CSV "ADUsers.csv"

or

Get-ADUser -Filter * -SearchBase "ou=OU,dc=Domain,dc=com" -Properties Enabled, CanonicalName, Displayname, Givenname, Surname, EmployeeNumber, EmailAddress, Department, StreetAddress, Title | select Enabled, CanonicalName, Displayname, GivenName, Surname, EmployeeNumber, EmailAddress, Department, Title | Export-CSV "C:\output.csv"

August 1, 2017 at 12:40 pm

Thanks a great deal!