Powershell Subselect / Active Directory
Budget: €10 – €20 EUR
i've a powershell command that selects informations from a organization-unit from a windows active directory.
Example-Code:
[String]$orgunit_DistinguishedName = "OU=User,OU=XYZ,DC=company,DC=com"
[array]$user_array=@()
$ou_user = get-aduser -filter {((Surname -ne "$null") -or (Surname -ne "$null")) -and (mail -ne "$null") -and (enabled -eq $true)} -Properties * -SearchScope subtree -SearchBase $orgunit_DistinguishedName | select-object Surname,givenName,UserPrincipalName,EmailAddress,OfficePhone,MobilePhone,personalTitle,Initials,Title,manager,Company,City
foreach ($_user in $ou_user){
$user_array+= [pscustomobject][ordered]@{
'FirstName'=$_user.givenname;
'LastName'=$_user.Surname;
'LoginName'= $_user.UserPrincipalName;
'OrgUnit_Customer-Nr' = "01";
'MainLocation_Customer-Nr'="01";
'MainLocation_Title'="test";
'Email'=$_user.EmailAddress;
'Salutation'="";
'Phone'=$_user.OfficePhone;
'MobilePhone'=$_user.MobilePhone;
'AcademicTitle'=$_user.personalTitle;
'InternalNumber'=$_user.Initials;
'JobTitel'=$_user.Title;
'BudgetLimit'="";
'Language'="";
'Supervisor_LoginName'="";
'Internal_Information'="";
'CostCenter'="";
'CostCenter_Customer-Nr'=""
}
}
$user_array | Format-Table
In the field "manager" i get the result:
CN=Mustermann Max,OU=Test,OU=User,OU=Location,DC=company,DC=com
and i want to get from this object (manager) no the user-principal logon name in the same result-set shown above.
for example: max.mustermann@company
Example-Code:
[String]$orgunit_DistinguishedName = "OU=User,OU=XYZ,DC=company,DC=com"
[array]$user_array=@()
$ou_user = get-aduser -filter {((Surname -ne "$null") -or (Surname -ne "$null")) -and (mail -ne "$null") -and (enabled -eq $true)} -Properties * -SearchScope subtree -SearchBase $orgunit_DistinguishedName | select-object Surname,givenName,UserPrincipalName,EmailAddress,OfficePhone,MobilePhone,personalTitle,Initials,Title,manager,Company,City
foreach ($_user in $ou_user){
$user_array+= [pscustomobject][ordered]@{
'FirstName'=$_user.givenname;
'LastName'=$_user.Surname;
'LoginName'= $_user.UserPrincipalName;
'OrgUnit_Customer-Nr' = "01";
'MainLocation_Customer-Nr'="01";
'MainLocation_Title'="test";
'Email'=$_user.EmailAddress;
'Salutation'="";
'Phone'=$_user.OfficePhone;
'MobilePhone'=$_user.MobilePhone;
'AcademicTitle'=$_user.personalTitle;
'InternalNumber'=$_user.Initials;
'JobTitel'=$_user.Title;
'BudgetLimit'="";
'Language'="";
'Supervisor_LoginName'="";
'Internal_Information'="";
'CostCenter'="";
'CostCenter_Customer-Nr'=""
}
}
$user_array | Format-Table
In the field "manager" i get the result:
CN=Mustermann Max,OU=Test,OU=User,OU=Location,DC=company,DC=com
and i want to get from this object (manager) no the user-principal logon name in the same result-set shown above.
for example: max.mustermann@company