Monday, October 17, 2022

Notes About Powershell: Accelerators

Accelerators

It is my understanding that many items in square brackets are "accelerators", which are what I would know as "aliases". You can get a list of Powershell objects that are accelerators like this:

PS >  [System.Management.Automation.PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get

Key                          Value                                                              
---                          -----                                                              
Alias                        System.Management.Automation.AliasAttribute                        
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute         
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute             
AllowNull                    System.Management.Automation.AllowNullAttribute                    
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute            
array                        System.Array                                                       
bool                         System.Boolean
  ...
pslistmodifier               System.Management.Automation.PSListModifier                        
psobject                     System.Management.Automation.PSObject                              
pscustomobject               System.Management.Automation.PSObject                              
psprimitivedictionary        System.Management.Automation.PSPrimitiveDictionary                 
  ...
CimSession                   Microsoft.Management.Infrastructure.CimSession                     
adsi                         System.DirectoryServices.DirectoryEntry                            
adsisearcher                 System.DirectoryServices.DirectorySearcher                         
wmiclass                     System.Management.ManagementClass                                  
wmi                          System.Management.ManagementObject                                 
wmisearcher                  System.Management.ManagementObjectSearcher                         
mailaddress                  System.Net.Mail.MailAddress                                        
scriptblock                  System.Management.Automation.ScriptBlock                           
psvariable                   System.Management.Automation.PSVariable                            
  ...

Notice the psobject accelerator. It's an accelerator ("alias") to System.Management.Automation.PSObject. This means that the above command can be shortened to:

PS >   [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get

Read more about accelerators here.

No comments: