foreach ($computer in $computername) {
$context = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ctype, $computer
$idtype = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName
$group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($context, $idtype, 'Administrators')
$group.Members | select @{N='Server'; E={$computer}}, @{N='Domain'; E={$_.Context.Name}}, samaccountName
}
Can someone describe this line? What does the "N" and "E" stand for?
select @{N='Server'; E={$computer}}, @{N='Domain'; E={$_.Context.Name}}, samaccountName
What I want is the output to look like the following and I want to flag the users in the admin group that are NOT apart of our standard setup. Really I want to ignore the SAM accounts that are the domain accounts but flagging them for now works. What is happening is there is a looping through the SAM accounts to create this output. However when the machine is offline I need to make that too.
You are looking at the short hand for the key and value of a calculated property. "N" is short for Name. "L" or Label is also used in place of Name. "E" of course is for Expression.
They are used when you want to manipulate existing properties or as a simple way to add properties. It is by no means the only way.
One of the Windows PowerShell Tips of the Week from TechNet delves into a great example:
Get-ChildItem C:\Test | Select-Object Name, CreationTime, @{Name="Kbytes";Expression={$_.Length / 1Kb}}
Length
is in bytes normally. A calculated property is used here to allow for a more human readable number. This is an example of manipulating a property.
In your case it looks like you are taking a list of members and creating output for each member while referencing the server it was attached to. Presumably that information is not normally present, hence the calculated property.
I am fairly sure that the "E" is shorthand for "Expression" and "N" is "Name"
The expression being the value and Name being the title of in this case the select statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With