At this point, you may notice a pattern. Commands to get information in PowerShell start with "Get-".
Moving on to Virtual Machine Manager (VMM), you can download the VMM cmdlet reference document here.
Here's an example from that document:
EXAMPLE 1: Copy a physical hard disk from a source machine to a virtual hard disk file.
PS C:\> $Credential = Get-Credential
PS C:\> Get-VMMServer -ComputerName "VMMServer1.Contoso.com"
PS C:\> $VMHost = Get-VMHost -ComputerName "VMHost01.Contoso.com"
PS C:\> Copy-HardDisk -SourceComputerName "P2VSource.Contoso.com" –VolumeDe
viceID "C" -Credential $Credential -VMHost $VMHost -Path "C:\MyVHDs" –Fixed
-DiskSizeAdd 1024
The first command uses Get-Credential to prompt you to supply a user name and password and stores your credentials in variable $Credential. The required credentials for this operation are either a local Administrator account or a domain account with administrator rights on the computer on which resides the physical hard disk that you want to convert to a virtual hard disk.
The second command connects to VMMServer1 in the Contoso.com domain and retrieves the server object from the Virtual Machine Manager database. The following commands use this server by default.
The third command gets the object that represents the host named VMHost01 in the Contoso.com domain and stores the host object in variable $VMHost.
The last command copies and converts the "C" volume located on the source computer named P2VSource (in the Contoso.com domain) into a new virtual hard disk (still named "C") and places it on VMHost01 at the specified path (C:\MyVHDs). The Fixed parameter specifies that the .vhd is fixed rather than dynamic in format and the DiskSizeAdd parameter increases the size of the volume by 1024 MB. As this command is processed, $Credential provides your credentials to Copy-HardDisk.
Here are some quick examples for IIS7.
To start and stop the Web server service, user the Start-Service and Stop-Service cmdlets.
Start-Service -servicename w3svc
Stop-Service -servicename w3svc
If you have the IIS WMI provider installed, then you can use the Get-WmiObject cmdlet to list the websites on the server.
Get-WmiObject -namespace "root\WebAdministration" -class Site
Obviously the Get-WmiObject cmdlet allows you to do a lot of things if you know which classes to work with. The way to do this is to use the –List parameter on Get-WmiObject. But this can produce a lot of information. For example, on my system:
PS (426) > (get-wmiobject -list).Count
930
There are 930 WMI classes available, so you need to be able to search for specific classes. In PowerShell you can do this with the Where-Object command, just like we did in the get service command example above, only this time we want to search on the name property. This command will find all of the WMI classes with "computersystem" in their name.
get-wmiobject -list | where {$_.name -match "computersystem" }
From this query, we find the Win32_ComputerSystem class. The next thing we might want to know is what properties this class has. We can use the Get-Member cmdlet to do this.
get-wmiobject Win32_ComputerSystem | get-member –type property
This lets us see that there is a property. Let's display this property in megabytes. We can do this as shown:
PS (26) > (get-wmiobject win32_computersystem).totalphysicalmemory / 1mb
2046.4765625
Another important source of information for administering a system is the event log. PowerShell lets you use the same approach to getting information from the event load as was used with other information sources. Here's an example that shows how to scan the 100 newest events in the event log for any errors.
get-eventlog system -newest 100 | where {$_.entrytype -eq "error" }
Other PowerShell tips
PowerShell is a shell, but it can also be loaded into other programs as an embedded scripting language, like Windows Scripting host (but using .NET instead of COM.) There are a number of examples where other people have built new "hosts" for PowerShell, such as PowerGUI and PowerShell Plus. It is also possible to use this technique to build a GUI overtop of the PowerShell engine so you can support both graphical and command line experiences.
Even with all of the fancy stuff, one thing to keep in mind is that PowerShell is still a shell or command-line interface just like cmd.exe. Sometimes people forget this and ask things like "how can I start notepad from PowerShell," thinking that you'll have to do something complex as you would in VBScript. But, because PowerShell is a shell, all you have to do to start notepad is to type "notepad."
Another shell-related questions we see is, "With cmd.exe, I use the attrib command. How would I do that in PowerShell?" The answer is use "attrib" just like in cmd.exe.
For more info, check out:
The Windows PowerShell Toolbox
The PowerShell script center
Windows PowerShell 2.0 CTP