Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Set-WmiInstance cmdlet.
What can I do with it?
Set an instance of a WMI class.
Example:
Change the value of MaxLogFileSize within the Win32_WMISetting class from the default of 6556 to 13112.
Set-WmiInstance -Class Win32_WMISetting -Argument @{MaxLogFileSize=13112}
You will notice that the MaxLogFileSize value is updated:
How could I have done this in PowerShell 1.
I was asked recently via Twitter how to find the CpuFeatureMask property of a VM using PowerCLI. When running a basic
Get-VM Test01 the below properties are outputted to the console:
It is possible to view more properties and values by runnning:
Get-VM Test01 | Format-List \* Unfortunately this still does not reveal the CpuFeatureMask property. However, if we pipe the Get-VM command through to Get-View we will get back a .
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Remove-WMIObject cmdlet.
What can I do with it?
Remove an instance of a WMI class.
Example:
Start Windows Calcultor. Retrieve the running process and terminate it.
calc Get-WmiObject Win32_Process -Filter “name=‘calc.exe’” | Remove-WmiObject
How could I have done this in PowerShell 1.0?
In the above example you could have called the Terminate method on the object returned in the WMI query.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Invoke-WMIMethod cmdlet.
What can I do with it?
Call WMI Methods.
Example:
Retrieve the WMI instances of the Print Spooler service. Pipe it through to Invoke-WMIMethod and call the StopService method.
Get-WmiObject Win32_Service -filter “name=‘spooler’” | Invoke-WmiMethod -Name StopService
Notice the service State changes.
How could I have done this in PowerShell 1.0?
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.
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.
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.
Remoting is one of the great new features in PowerShell 2.0. If you wish to deploy PowerShell 2.0 and remoting within your Enterprise you probably don’t want to run Enable-PSRemoting on every single server where you have installed PowerShell 2.0. The smart way is of course to use Group Policy. You will need to ensure the following:
Enable the policy Computer Configuration\Policies\Administrative Templates\Windows Components\Windows Remote Management\WinRM Service\Allow automatic configuration of listeners, specifying IPv4 and V6 subnets where appropriate: If you have Windows Firewall enabled on your servers you will need to make a policy setting to allow inbound Windows Remote Management.
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.
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.