Have you ever heard about PowerShell Accelerators?
It is what makes it easy to handle stuff like XML files, WMI Objects or Active Directory Objects.
We use it for pre-defining variable and calculations types too.
for example we can read a XML file using [xml] and get-content
PS C:\> $xml = [xml] (Get-Content myXMLFile.xml)
by using this method we are able to parse the XML into real PS objects, and therefore we can acess the parts by using the dot net way.
PS C:\> $xml.Config.ServerName
This will read the ServerName Tag inside the Config tag.
Problem is that there is a lot of these, and no official complete list.
One of the reasons is that, new accelerators might become available, when you import modules.
But by using these few lines of code you will get the complete list of available accelerators:
$acceleratorsType = [type]::gettype("System.Management.Automation.TypeAccelerators") $acceleratorsType::Add("accelerators", $acceleratorsType) [accelerators]::Get
On my windows 7 PC I have the following list (no extra modules is loaded)
Key Value
— —–
int System.Int32
long System.Int64
string System.String
char System.Char
bool System.Boolean
byte System.Byte
double System.Double
decimal System.Decimal
float System.Single
single System.Single
regex System.Text.RegularExpressions.Regex
array System.Array
xml System.Xml.XmlDocument
scriptblock System.Management.Automation.ScriptB…
switch System.Management.Automation.SwitchP…
hashtable System.Collections.Hashtable
type System.Type
ref System.Management.Automation.PSRefer…
psobject System.Management.Automation.PSObject
pscustomobject System.Management.Automation.PSObject
psmoduleinfo System.Management.Automation.PSModul…
powershell System.Management.Automation.PowerShell
runspacefactory System.Management.Automation.Runspac…
runspace System.Management.Automation.Runspac…
ipaddress System.Net.IPAddress
wmi System.Management.ManagementObject
wmisearcher System.Management.ManagementObjectSe…
wmiclass System.Management.ManagementClass
adsi System.DirectoryServices.DirectoryEntry
adsisearcher System.DirectoryServices.DirectorySe…
psprimitivedictionary System.Management.Automation.PSPrimi…
accelerators System.Management.Automation.TypeAcc…
As you can see , there is a lot of them!
you can even create your own. Read this blog post
On of the cooler ones is [adsisearcher].
All it need is a AD query as input I you will have the result in the variable.
Actually if you are familiar with .net programming, you know that types in .net is named fx:
[System.Net.NetworkInformation.IPStatus]
Thanks to the great forum reply about this subject, you can read it here: http://stackoverflow.com/questions/1145312/where-can-i-find-a-list-of-powershell-net-type-accelerators
Exactly what I was looking for,
Thanks for posting Jacob
Regards
Ernie
Great article Jacob! We’ve recently written a blog on PowerShell Type Accelerators – shortcuts to .NET classes that might be of interest:
http://www.ravn.co.uk/powershell-type-accelerators-shortcuts-dotnet-classes/
Would be good to hear your thoughts.