Link to home
Start Free TrialLog in
Avatar of SAM2009
SAM2009Flag for Canada

asked on

Need help to understand Powershell code.

Hi,

Is someone can tell me what is the difference between "Get-ADUser User -Properties UserPrincipalName | select SamAccountName,UserPrincipalName" and ""Get-ADUser User | select SamAccountName,UserPrincipalName" because I got same result when I export it to csv:

1)
----------------------------------------------------------------------------------------------------
$SamAccount = Import-Csv "C:\SamAccountName.csv"

$SamAccount | % {Get-ADUser $_.SamAccountName -Properties UserPrincipalName | select SamAccountName,UserPrincipalName

} | Export-csv "C:\UserPrincialName.csv" -NoTypeInformation
----------------------------------------------------------------------------------------------------

2)
----------------------------------------------------------------------------------------------------

$SamAccount = Import-Csv "C:\SamAccountName.csv"

$SamAccount | % {Get-ADUser $_.SamAccountName | select SamAccountName,UserPrincipalName

} | Export-csv "C:\UserPrincialName.csv" -NoTypeInformation
----------------------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
FYI, the default properties are:
DistinguishedName
Enabled          
GivenName        
Name            
ObjectClass      
ObjectGUID      
SamAccountName  
SID              
Surname          
UserPrincipalName
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM2009

ASKER

Ok but what the difference between -properties and -property?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM2009

ASKER

Thanks all for your help!