Skip navigation
John Savill'ss FAQs on IT Pro Today Hero

Savill's FAQs: PowerShell parameters & removing array entries

Three times a week, John Savill tackles your most pressing IT questions. Today we learn about how to find latencies between data centers in Azure Regions & Availability Zones, short parameters for cmdlets & removing array entries in PowerShell commands.

Three times a week (Monday/Wednesday/Friday), John Savill tackles your most pressing IT questions.

Read through the FAQ archives, or send him your questions via email.

Today: Learn about how to find latencies between data centers in Azure Regions & Availability Zones, short parameters for cmdlets & removing array entries in PowerShell commands.


Q. What are the latencies between datacenters within an Azure region and Availability Zone?

A. At Ignite 2017 Mark Russinovich gave a session on the internals of Azure. In that session he disclosed the definition of a region and Availability Zone.

  • A region is a latency envelope of <2 ms (round trip)
  • An Availability Zone is one or more datacenters within a 600 μs (microsecond) latency (.6 ms)

Q. How can I find the short version of parameters for a cmdlet?

A. Just like in regular PowerShell, the parameters used with a PowerShell command can have an alias. It can sometimes be difficult to know what the short version of the parameters actually are but unsurprisingly you can find them using PowerShell.

There are a number of steps which really revolves around getting the details of a command using Get-Command and then for that command looking at the parameter objects and their name and aliases attributes.

For example for Get-Process:

(get-command Get-Process).Parameters.Values | Select-Object name, aliases

This shows:

PS C:\Users\john> (get-command Get-Process).Parameters.Values | Select-Object name, aliases 

Name                Aliases      
----                -------      
Name                {ProcessName}
Id                  {PID}        
InputObject         {}           
IncludeUserName     {}           
ComputerName        {Cn}         
Module              {}           
FileVersionInfo     {FV, FVI}    
Verbose             {vb}         
Debug               {db}         
ErrorAction         {ea}         
WarningAction       {wa}         
InformationAction   {infa}       
ErrorVariable       {ev}         
WarningVariable     {wv}         
InformationVariable {iv}         
OutVariable         {ov}         
OutBuffer           {ob}         
PipelineVariable    {pv}    

This will show those even where there is no alias. To just show those with an alias we can add:

PS C:\Users\john> (get-command Get-Process).Parameters.Values | where aliases | Select-Object name, aliases 

Name                Aliases      
----                -------      
Name                {ProcessName}
Id                  {PID}        
ComputerName        {Cn}         
FileVersionInfo     {FV, FVI}    
Verbose             {vb}         
Debug               {db}         
ErrorAction         {ea}         
WarningAction       {wa}         
InformationAction   {infa}       
ErrorVariable       {ev}         
WarningVariable     {wv}         
InformationVariable {iv}         
OutVariable         {ov}         
OutBuffer           {ob}         
PipelineVariable    {pv}     

Q. How can I remove an entry from an array in PowerShell?

A. The easiest way to remove an entry is to copy into a new array minus the item you want to remove. In this example I have an array of custom objects and I want to remove one that has a code of RemoveMe.

$Objects = $Objects | where { $_.Code -ne "RemoveMe"}

As you can see the existing array is sent down the pipeline where the objects continue providing the object ($_) does not have a code equal to "RemoveMe". Pretty simple but effective.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish