Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Need hep figuring out how to properly reference variable properties

$
0
0

I have a script with the following code

$PrincipalList=Import-Csv".\Server01 Local Administrators Group.csv"

 

 

 

foreach

 

 

($Principalin$PrincipalList){

 

 

 

$LocalSysAdminsInDomain=$Principal|Where-Object {$Principal.Domain -eq"Subdomain.Example.Com"} |Select-Object {$Principal.SamAccountName,$Principal.Domain}

 

 

 

Write-Host$LocalSysAdminsInDomain

 

 

 

Write-Host$LocalSysAdminsInDomain.samaccountname

Write-Host$Principal.samaccountname

}

I'm apparently incorrectly referencing the samaccountname propertly of the $LocalSysAdminsInDomain variable incorrectly, as I get absolutely nothing returned.  I do however get something when I output strictly the $LocalSysAdminsInDomain variable.  What I get is when I output this is

 {Domain Admins, Subdomain.Example.Com}

I also get what I expect when I output $Principal.samaccountname.  I get returned all rows of the SamAccountName column

 

Domain Admins is in the SamAccountName column and Subdomain.Example.Com is in the Domain column of the csv file.

I'm not really sure which direction to go in at this moment to properly return

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles