how can get all users details from single forest and its child domains

Hi

While trying to get all users details from below script getting below error:

I  understand that error is valid but I am trying to get all users from forest having 4 child domain , user properties..

Please add or guide me on this

Import-Module ActiveDirectory
$forest= (Get-ADForest).domains
$Outfile = "D:\script\SIPuserdetails.csv"
Get-ADUser -Filter {(msRTCSIP-UserEnabled -eq $False) -and (enabled -eq $True)} -Server $forest -Properties * | select name,samaccountname,msRTCSIP-PrimaryUserAddress

Error###########

PS D:\temp> .\SearchSIPusers.ps1
Get-ADUser : Cannot convert 'Microsoft.ActiveDirectory.Management.ADPropertyVal
ueCollection' to the type 'System.String' required by parameter 'Server'. Speci
fied method is not supported.
At D:\temp\SearchSIPusers.ps1:19 char:88
+ Get-ADUser -Filter {(msRTCSIP-UserEnabled -eq $False) -and (enabled -eq $True
)} -Server <<<<  $forest -Properties * | select name,samaccountname,msRTCSIP-Pr
imaryUserAddress
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBind
   ingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.
   Management.Commands.GetADUser



  • Edited by Mr. Raj 15 hours 37 minutes ago
April 21st, 2015 11:34am

The server parameter takes a string value, you are passing it an array of strings.

You will need to loop through $forest, passing the value to the server

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 11:38am

Thanks Calyman2

you are rockstar..

But I need to get domain name in user property as well..

how can I get that user belongs to which domain in output file..

April 21st, 2015 11:56am

Have you tried adding UserPrincipalName to the Select-Object at the end? If that isn't what you want then you can add the following to the Select-Object get just the domain name

@{N='Domain';E={$_.CanonicalName.Split('/')[0]}}

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 1:00pm

I used userprinicipal in below format:

@{n="domain Name"; e={$_.userPrincipalName}}

But I am getting full userprincipalname ,, I am looking only domain name instead of testuser@test.contoso.com

I need only"test.contoso.com"

Please suggest more on this..

April 21st, 2015 1:20pm

But Thanks..

I got domain details after applied solution, which you have provided..

Thanks a lot.. you are really champ and master..

hats-off to you sir.

@{N='Domain';E={$_.CanonicalName.Split('/')[0]}}
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 1:22pm

You're welcome, glad I could help
April 21st, 2015 1:27pm

I used userprinicipal in below format:

@{n="domain Name"; e={$_.userPrincipalName}}

But I am getting full userprincipalname ,, I am looking only domain name instead of testuser@test.contoso.com

I need only"test.contoso.com"

Please suggest more on this..

@{n="domain Name"; e={$_.userPrincipalName.Split('@')[1]}}


Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 1:27pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics