quinta-feira, 25 de agosto de 2016

Powershell - Array/Tables

To declare or create a array/table:

$Table1 = @()


To add item to the array/table:

$Table1 =  New-Object psobject -Property @{Name=$($Name);Age=$($Age)}

In red is the column name.

In blue is the variable of the item.


To append item to the array/table:

$Line =  New-Object psobject -Property @{Name=$($Name);Age=$($Age)}

In red is the column name.

In blue is the variable of the item.

$Table1 += $Line


To add a new column:

Select-Object *,@{Name='Address';Expression={$Address}}

P.S.: This will add the same address to all items!


To sort a array/table by column (name)

$Table1 | Sort Name


To get the number of lines

$Table1.count


To get unique values

$Table1 | Select -unique


To find a string in the array

$MissingSubnets -match $Data

Nenhum comentário:

Postar um comentário