Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the N and E represent in this select statement

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.

EXample Output

like image 726
Bradley Smith Avatar asked May 12 '15 20:05

Bradley Smith


2 Answers

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.

like image 80
Matt Avatar answered Nov 25 '22 22:11

Matt


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.

like image 35
Luke Avatar answered Nov 25 '22 22:11

Luke