by athreyatoo43 at 2013-02-11 06:03:25
can someone help me with the script to get the samaccountname of a list of users by their display names.by coderaven at 2013-02-11 07:54:26
I would suggest to use the ActiveDirectory module that comes with the RSAT toolsby athreyatoo43 at 2013-02-12 03:52:43Import-Module ActiveDirectory
Get-Content -Path \Path\to\File.txt | foreach-object { Get-ADUser -Identity $_ | Select Name, SamAccountName }
Does this ouput the file ? if so, where does it ? and what format.by athreyatoo43 at 2013-02-12 04:17:23
I want to give a excel or csv as input and want an excel sheet as output. please help
I Get the below errorby Klaas at 2013-02-12 05:03:07
PS C:\Windows\system32> cd<br>PS C:> cd users\ushasp\desktop
PS C:\users\ushasp\desktop> Import-Module ActiveDirectory
PS C:\users\ushasp\desktop> Get-Content -Path DIsplay-Names.txt
Rajesh Bondu
Nakul AR
PS C:\users\ushasp\desktop> foreach-object { Get-ADUser -Identity $_ | Select Name, SamAccountName }
Get-ADUser : Cannot validate argument on parameter ‘Identity’. The argument is null. Supply a non-null argument and try
the command again.
At line:1 char:38
+ foreach-object { Get-ADUser -Identity <<<< $_ | Select Name, SamAccountName }
+ CategoryInfo : InvalidData: ( [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
If you execute the Get-Content cmdlet alone, the result is written to the screen. After that you use the Foreach cmdlet but there is nothing in the pipe.by athreyatoo43 at 2013-02-12 07:46:44
You really have to use both cmdlets in combination, with the | in between, exactly as coderaven wrote.
If you want to write this to a file, add| export-csv C] at the end.
HI Klaas, i am very bad at scripting… could you please give me the complete script at once…by Klaas at 2013-02-12 08:22:57
Import-Module ActiveDirectory
Get-Content -Path C:\users\ushasp\desktop\DIsplay-Names.txt |
foreach-object { Get-ADUser -Identity $_ | Select Name, SamAccountName }|
export-csv C]