cmdlet-series

PowerShell 2.0: One Cmdlet at a Time 88 Export-FormatData

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Export-FormatData cmdlet. What can I do with it? Take formatting data generated by Get-FormatData and export it to a *.ps1xml file. Example: Retrieve the formatting for the TypeName Microsoft.Win32.RegistryKey and export it to a *.ps1xml file. Get-FormatData -TypeName Microsoft.Win32.RegistryKey | Export-FormatData -Path registryformat.ps1xml -IncludeScriptBlock The contents of registryformat.ps1xml are shown below. How could I have done this in PowerShell 1.

PowerShell 2.0: One Cmdlet at a Time 87 Get-FormatData

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-FormatData cmdlet. What can I do with it? Retrive format data from the current session. Within a session formatting data could include formatting from *.ps1xml format files stored in the PowerShell installation directory, formatting from imported modules or snapins, or formatting from commands imported with Import-PSSession. Example: Retrieve the formatting for the TypeName Microsoft.

PowerShell 2.0: One Cmdlet at a Time 86 ConvertTo-XML

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the ConvertTo-XML cmdlet. What can I do with it? Convert a .NET object into an XML-based representation of it. Example: Retrieve a list of services beginning with the letter b and convert the object into an XML-based respresentation. Use the available Save method of the XML object to save the data into an XML file.

PowerShell 2.0: One Cmdlet at a Time 85 ConvertFrom-StringData

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the ConvertFrom-StringData cmdlet. What can I do with it? Converts a string which contains one or multiple key and valuepairs into a hash table. Input is typically from a here-string since each key and value must be on a separate line. Example: Create a here-string and store it in the variable $herestring. Convert it into a hash table.

PowerShell 2.0: One Cmdlet at a Time 84 ConvertFrom-CSV

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the ConvertFrom-CSV cmdlet. What can I do with it? Convert a series of CSV style strings which have been generated by ConvertTo-CSV back into objects. Example: Retrieve a list of services beginning with the letter b and convert the object into CSV style strings, storing them into the variable $CSVStrings . Convert these back into objects.

PowerShell 2.0: One Cmdlet at a Time 83 ConvertTo-CSV

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the ConvertTo-CSV cmdlet. What can I do with it? Convert a .NET object into a series of CSV style strings. Example: Retrieve a list of services beginning with the letter b and convert the object into CSV style strings Get-Service | Where-Object{$_.Name -like ‘b*’} | ConvertTo-CSV -NoTypeInformation You will notice that the data returned from the services has been converted into strings separated by a comma.

PowerShell 2.0: One Cmdlet at a Time 82 Use-Transaction

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Use-Transaction cmdlet. What can I do with it? PowerShell 2.0 introduces new functionality in the form of transactions. By grouping together a set of commands to form a transaction they can either all be committed or all rolled back depending on success. Use-Transaction enables you to add a scriptblock to a transaction. Note: This only works with transaction-enabled .

PowerShell 2.0: One Cmdlet at a Time 81 Undo-Transaction

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Undo-Transaction cmdlet. What can I do with it? PowerShell 2.0 introduces new functionality in the form of transactions. By grouping together a set of commands to form a transaction they can either all be committed or all rolled back depending on success. Undo-Transaction rolls back the active transaction. Example: A good example of a possible use for transactions is within the registry.

PowerShell 2.0: One Cmdlet at a Time 80 Get-Transaction

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-Transaction cmdlet. What can I do with it? PowerShell 2.0 introduces new functionality in the form of transactions. By grouping together a set of commands to form a transaction they can either all be committed or all rolled back depending on success. Get-Transaction returns an object of a current transaction which has been kicked off with Start-Transaction.

PowerShell 2.0: One Cmdlet at a Time 79 Complete-Transaction

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Complete-Transaction cmdlet. What can I do with it? PowerShell 2.0 introduces new functionality in the form of transactions. By grouping together a set of commands to form a transaction they can either all be committed or all rolled back depending on success. Complete-Transaction commits a transaction which has been kicked off with Start-Transaction.