Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
Complete the form below to send this article, Windows 8 and Windows Server 2012 Modules and Cmdlets, to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.
Microsoft Windows PowerShell 3.0 First Look will ensure that you have a great overview of the numerous new features and changes found in the most recent version of the language. Through simple examples and succinct chapters, this book will quickly bring readers up to speed with need to know information about the newest version of PowerShell.
In this article by Adam Driscoll, author of Microsoft Windows PowerShell 3.0 First Look, we'll see:
- A selection of new cmdlets found in the core PowerShell modules
- A selection of new modules and cmdlets found in Windows 8 and Windows Server 2012
Core modules
These modules are installed by default in both Windows 8 and Windows Server 2012. These cmdlets will be available on machines that are running the latest version of the Windows Management Framework as well.
Invoke-WebRequest
In the previous version of PowerShell, a .NET class was required to access web-based content. In PowerShell 3.0, the same can be accomplished by utilizing the Invoke-WebRequest cmdlet. The cmdlet returns an object HttpWebResponseObject that contains all kinds of information about the HTTP request such as the response code, the response content, and even parsed elements within the page, such as links and forms.
Usage examples
The following example retrieves a pages links, selects the first three, and outputs their innerHTML and destination:
PS C:\> Invoke-WebRequest www.microsoft.com |
Select-Object -ExpandProperty links
| Select-Object -First 3 –Property innerHtml,href
innerHTML href
--------- ----
Windows http://windows.microsoft...
The following example retrieves the first image found on www.microsoft.com and displays it in the default web browser:
PS C:\ > Start-Process (invoke-webrequest -Uri http://www.microsoft.com |
Select-Object -ExpandProperty images
| Select-Object -First 1 -ExpandProperty Src)
Invoke-RestMethod
This cmdlet is used to invoke Representational State Transfer (REST) methods.
REST is a client/server architecture based on resource types and state. Universal Resource Identifiers (URI), are used to access different resources within a RESTful service. Typically, RESTful services utilize the existing HTTP protocol to communicate between the client and server.
Usage examples
The following example invokes a REST method using the HTTP GET method to retrieve a particular resource on the mydomain.com server. It is expected that the result will be returned as JSON:
Invoke-RestMethod –Uri http://www.mydomain.com/group/1/user/123
-Method GET -ReturnType Json
ConvertTo-Json
This cmdlet is used to convert objects in PowerShell into JavaScript Object Notation (JSON). JSON is used to serialize object structures to a string so that it can be sent in between a client and server. JSON is frequently used on wide area networks because its syntax is much more succinct than schemes such as XML.
Usage examples
The following example converts an object to JSON:
PS C:\> Get-Variable PSUICulture | ConvertTo-Json
{
"Value": "en-US",
"Name": "PSUICulture",
"Description": "UI Culture of the current Windows PowerShell Session.",
"Visibility": 0,
"Module": null,
"ModuleName": "",
"Options": 9,
"Attributes": [
]
}
The following example converts an object to JSON that has members added at runtime:
PS C:\> Get-Random | Add-Member -MemberType NoteProperty
-Value "MyValue" -Name "MyProperty" –PassThru | ConvertTo-Json
{
"value": 1705462562,
"MyProperty": "MyValue"
}
The following example shows that the ConvertTo-Json treat data types like strings and integers differently than the objects shown previously. Notice that there is no length property serialized in this example, even though the string class exposes it.
PS C:\> "MyString" | ConvertTo-Json
"MyString"
PS C:\> Get-Random | ConvertTo-Json
1231
ConvertFrom-Json
This cmldet is used to convert a JSON string into an object that can be used in PowerShell. Unlike the ConvertTo-CliXml, the ConvertFrom-Json cmdlet does not preserve type data and will simply be of the type PSCustomObject. Particular data types can be converted into their object representation if put in the correct format.
Usage examples
The following example shows that the JSON string in the example is converted into a PSCustomObject with a property DateTime that is a String type:
PS C:\ > '{ "DateTime": "Thursday, February 23, 2012 7:56:18 PM" }'
| ConvertFrom-Json | Get-Member -Name Date
Time
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
DateTime NoteProperty System.String DateTime=Thursday,
February 23, 2012 7:56:18 PM
The following example shows that particular data type formats, in this case a date, are passed to the ConvertFrom-Json cmdlet, it will be able to convert it to a .NET class:
PS C:\ > '{ "DateTime": "\/Date(1330048578834)\/" }'
| ConvertFrom-Json | Get-Member -Name DateTime
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
DateTime NoteProperty System.DateTime
DateTime=2/24/2012 1:56:18 AM
ControlPanelItem
The Get-ControlPanelItem and Show-ControlPanelItem cmdlets are used to list and show control panel items that are currently installed on the system. Using the Show-ControlPanelItem will cause the control panel window to be shown immediately.
Usage examples
The following example gets the Mouse control panel item and shows the Name, Category and Description properties:
PS C:\> Get-ControlPanelItem -Name Mouse
| Select-Object Name,Category,Description
Name Category Description
---- -------- -----------
Mouse {All Control Panel Items}Customize your...
The following example shows the Fonts control panel item using the canonical name:
PS C:\> Show-ControlPanelItem -CanonicalName Microsoft.Fonts
Rename-Computer
This cmdlet is used to rename local or remote computers. The cmdlet can use both local or domain credentials and can trigger a restart.
Usage examples
The following example renames the computer driscoll-hv1 to driscoll-hv2 using the domain credentials. The command also bypasses confirmation and causes a restart of the machine:
PS C:\> Rename-Computer –ComputerName driscoll-hv1
–NewName driscoll-hv2 –DomainCredential mdn\administrator –Force –Restart
TypeData
The TypeData cmdlets are used for managing the Extended Type System (ETS), type data that has been loaded into PowerShell. This type data is added through *.types.ps1xml files and are typically found in modules.
Usage examples
The following example returns the ETS type data for the System.Management.ManagementObject class and displays the added ETS members:
PS C:\ > Get-TypeData System.Management.ManagementObject
| Select-Object -ExpandProperty Members
Key Value
--- -----
ConvertToDateTime ...ScriptMethodData
ConvertFromDateTime ...ScriptMethodData
The following example removes the ETS type data for the System.Guid class:
PS C:\ > [System.Guid]::NewGuid() | Get-Member –Name Guid
TypeName: System.Guid
Name MemberType Definition
---- ---------- ----------
Guid ScriptProperty System.Object Guid {get=$this.ToString();}
PS C:\ > Remove-TypeData –TypeName System.Guid
PS C:\ > [System.Guid]::NewGuid() | Get-Member –Name Guid
PS C:\ >
Unblock-File
This cmdlet is used to remove the alternate data stream from the file, known as the zone identifier. The zone identifier signifies that the file has come from the Internet and PowerShell will warn or prevent you from executing scripts with this zone identifier. This can become very hard to deal with when a lot of files are involved, such as with a module. The Unblock-File cmdlet makes this much easier.
Usage examples
The following example removes the zone identifier from the Test.ps1 file:
PS C:\> Unblock-File –Path C:\Users\Adam\Documents\Test.ps1
The following example unblocks all the files in the HyperV module directory:
PS C:\> Get-ChildItem -Path C:\Users\Adam\Documents\WindowsPowerShell\ Modules\HyperV | Unblock-File
Standard modules
These modules are part of the standard set of modules available on Windows 8 and Windows Server 2012 machines. They are not available to users who install the Windows Management Framework on machines such as Windows 7 or Windows Server 2008 R2. No features or roles are required to access any of these modules and most of them are based on CIM providers so they support CIM sessions.
NetAdapter module
This module is available for the users running Windows 8 and Windows Server 2012 and it requires no feature. It contains a total of 64 cmdlets. The following command shows how to import this module:
PS C:\ > Import-Module NetAdapter
The NetAdapter module exposes cmdlets that manage the network adapters, protocol bindings, and numerous other network related operations. The module is enabled by default and there are no features that need to be installed to enable it. The cmdlets in this module are based on CIM and support CIM sessions.
NetAdapter cmdlets
These cmdlets allow us to manage the network adapters that are currently installed on the system. The Get-NetAdapter allows us to retrieve them. The Set-NetAdapter allows us to change the MAC and VLAN ID of the adapters. The Enable-NetAdapater, Disable-NetAdapter, and Restart-NetAdapter allow us to change the state of the adapter.
Usage examples
The following example returns all the network adapters on the local machine:
PS C:\> Get-NetAdapter
Name Interface MacAddress Operational LinkSpeed
Index Status
---- --------- ---------- ----------- ---------
Wired... 12 00-15-5D-91-3A-0C Up 10 Gbps
The following example resets the network adapters that match the name Wired*:
PS C:\> Get-NetAdapter Wired* | Restart-NetAdapter
The following example sets the VLAN ID of all the network adapters that match the name Wired*:
PS C:\> Get-NetAdapter Wired* | Set-NetAdapter –VLANID 3
NetAdapterBinding
Theses cmdlets let us manage the network bindings for the various interfaces defined in the local or remote system. In addition to seeing the current defined bindings, such as TCP/IP v4, we can enable and disable the bindings for particular interfaces.
Usage examples
The following example returns the network bindings that match the display name *TCP/IPv4*:
PS C:\ > Get-NetAdapterBinding -DisplayName *TCP/IPv4*
Name DisplayName ComponentID Enabled
---- ----------- ----------- -------
Wired...Internet... ms_tcpip True
The following example disables all network adapter bindings that match the display name *TCP/IPv6*:
PS C:\ > Get-NetAdapterBinding -DisplayName *TCP/IPv6* | Disable- NetAdapterBinding
NetAdapaterAdvancedProperty
These cmdlets are used for managing some of the advanced properties for network adapters. Some of these properties include receive buffer size and TCP checksum offload for IPv4 and IPv6. We can retrieve the properties using the Get-NetAdapterAdvancedProperty cmdlet and set them using the Set-NetAdapterAdvancedProperty cmdlet. We can even create new properties using the New-NetAdapterAdvancedProperty cmdlet.
Usage examples
The following example gets the Receive Buffers advanced NetAdapter property:
PS C:\> Get-NetAdapterAdvancedProperty –DisplayName "Receive Buffers"
| Select-Object -ExpandProperty RegistryValue
512
The following example enables the Jumbo Packet advanced NetAdapter property:
PS C:\> Set-NetAdapterAdvancedProperty –Name "Wired Ethernet Connection"
–DisplayName "Jumbo Packet" –Value "Enabled"
SmbShare module
This module is available in Windows 8 and Windows Server 2012 and it does not require any feature as well. There are a total of 23 cmdlets in this module. The following command is used to import it:
PS C:\> Import-Module SmbShare
The SmbShare module is used to manage Server Message Block (SMB) shares, connections, and other share related information on a Windows machine. The cmdlets found within the module can create new shares, configure permissions, and enumerate connections to the shares. The cmdlet can also control SMB client configuration settings and network interfaces used for the SMB connections. The cmdlets within this module are native CIM cmdlets and support CIM sessions.
SmbShare
The SmbShare cmdlets allow for enumeration, creation, removal, and access control of the SMB shares on the current server.
Usage examples
The following example selects the first SMB share:
PS C:\ > Get-SmbShare | Select-Object –First 1
Name ScopeName Path Description
---- --------- ---- -----------
ADMIN$ * C:\Windows Remote Admin
The following example creates a new SMB share with the name Share and the path C:\Share:
PS C:\> New-SmbShare –Path C:\Share –Name Share
The following example removes the SMB share named Share:
PS C:\> Remove-SmbShare –Name Share
SmbSession
These cmdlets are used for managing sessions that currently are connected to the SMB shares on the local or remote machine.
Usage examples
The following example enumerates the current SMB session connections on the local machine:
PS C:\ > Get-SmbSession
SessionId ClientComputerName ClientUserName NumOpens
--------- ------------------ -------------- --------
377957122073 \\[fe80::952f:e0... MDN\Administrator 3
The following example closes all the SMB session connections for the mdn\administrator user on the local machine:
PS C:\> Get-SmbSession -ClientUserName mdn\administrator | Close-SmbSession
SmbShareAccess
These cmdlets are used to retrieve, grant, and revoke SMB share access.
Usage examples
The following example retrieves a share's access control list:
PS C:\ > Get-SmbShareAccess -Name Share
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
Share * Everyone Allow Read
The following example revokes the Full access right to a SMB share from the Everyone user group:
PS C:\> Get-SmbShareAccess –Name Share | Revoke-SmbShareAccess
– AccountName Everyone
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
Share * Everyone Deny Full
The following example completely blocks a share access without specifying the access control type:
PS C:\> Block-SmbShareAccess –Name Share
–AccountName Everyone
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
Share * Everyone Deny Full
Share * Everyone Allow Full
SmbOpenFile
These cmdlets are intended to enumerate and close open files and directories that are being served through SMB shares on the local or remote machine.
Usage examples
The following example gets a list of open SMB files:
PS C:\> Get-SMBOpenFile | Select-Object
ClientComputerName,ClientUserName ,Path
ClientComputerName ClientUserName Path
------------------ -------------- ----
\\10.0.0.3 MDN\Administrator C:\\Users\Administrator
\\10.0.0.3 MDN\Administrator C:\\Users\Administ...
The following example closes all the open SMB files and directories for a particular user:
PS C:\ > Get-SmbOpenFile -ClientUserName mdn\administrator
| Close- SmbOpenFile
Confirm
Are you sure you want to perform this action?
Performing operation 'Close-File' on Target '395136991761'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?]
Help (default is "Y"): a
PrintManagement module
This module is available in Windows 8 and Windows Server 2012 and no feature is required. There are a total of 18 commands. The following command is used to import this module:
PS C:\> Import-Module PrintManagement
This module is used for managing printers, print drivers, printer configuration, and print jobs. These cmdlets are based on CIM classes and support CIM sessions.
Printer
These cmdlets are used for retrieving, adding, removing, and modifying printers.
Usage examples
The following example gets the OneNote printer and displays its name, type, driver name, and port:
PS C:\ > Get-Printer -Name *OneNote* |
Select-Object Name,Type,DriverName,PortName
Name Type DriverName PortName
---- ---- ---------- --------
OneNote... Local Remote Desktop Easy Print TS014
The following example sets the comment on the XPS Document Writer printer:
PS C:\> Get-Printer -Name "Microsoft XPS Document Writer"
| Set-Printer -Comment "Local Printer"
PrintJob
These cmdlets manage running and historic printer jobs. Jobs can be stopped, paused, restarted, and resumed.
Usage examples
The following example stops all printer jobs that are currently running on the Microsoft XPS Document Writer:
PS C:\> Get-Printer -Name "Microsoft XPS Document Writer"
| Get-PrintJob | Remove-PrintJob
PrintConfiguration
These cmdlets get and set the print configuration for a printer.
Usage examples
The following example returns the print configuration for the Microsoft XPS Document Writer printer:
PS C:\ > Get-Printer -Name "Microsoft XPS Document Writer"
| Get- PrintConfiguration
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
Microsoft XP... False True OneSided
Windows data access control module
This module is available in Windows 8 and Windows Server 2012 and it requires no feature. There are a total of 12 cmdlets in this module. The following command is used to import this module:
PS C:\> Import-Module wdac
The WDAC module is used for managing ODBC connections. This module is based on CIM classes and supports CIM sessions.
OdbcDsn
These cmdlets are used for managing ODBC Data Source Names (DSN) defined on the local or remote system. It's possible to enumerate, create, update, and remove a DSN.
Usage examples
The following example creates a new ODBC DSN on the local machine named InternalDsn, connecting the SQL Server ODBC driver to the database LocalDatabase stored on the server sql2008. Note that depending on the driver, the property values may vary:
PS C:\ > Add-OdbcDsn -Name InternalDsn -DsnType User
-DriverName "SQL Server" -SetPropertyValue @("Database=LocalDatabase","Server=sql2008")
The following example retrieves the defined ODBC DSNs on the local machine:
PS C:\ > Get-OdbcDsn
Name : InternalDsn
DsnType : User
Platform : 32/64-bit
DriverName : SQL Server
Attribute : {Server, Database}
OdbcDriver
These cmdlets are used for managing the ODBC drivers that are installed on the system. ODBC drivers are used to connect to different types of databases.
Usage examples
The following example gets the 64-bit ODBC drivers on the local machine and formats the output as a list:
PS C:\ > Get-OdbcDriver –Platform 64-bit | Format-List
Name Platform Attribute
---- -------- ---------
SQL Server 64-bit {Driver, APILevel, FileUsage,...}
DnsClient module
This module is available in Windows 8 and Windows Server 2012 and it requires no feature. There are a total of 15 cmdlets.
PS C:\> Import-Module DnsClient
The DnsClient module offers cmdlets for interacting with the local DNS client. This includes cmdlets for resolving DNS names, viewing the cached DNS records, and enumerating DNS servers. This cmdlet is based on a CIM provider and can utilize CIM sessions.
Resolve-DnsName
This cmdlet resolves the specified name to an IP address. This cmdlet offers many different kinds of filtering options. It also allows for queries based on DNS record type, such as A and AAAA.
Usage examples
The following example resolves the computer name driscoll-laptop:
PS C:\ > Resolve-DnsName –Name driscoll-laptop
| Format-List
Name : driscoll-desk
Type : AAAA
TTL : 30
DataLength : 16
Section : Answer
IPAddress : fe80::48d1:aec:7a7a:1a8
Name : driscoll-desk
Type : A
TTL : 30
DataLength : 4
Section : Answer
IPAddress : 10.0.0.8
DnsClientCache
These cmdlets are used for viewing and clearing the DNS client cache records.
Usage examples
The following example returns a list of the DNS records currently in the DNS cache and selects the name of the device:
PS C:\ > Get-DnsClientCache| Select-Object -Property Name
Name
----
driscoll-laptop
sqm.telemetry.microsoft.com
driscoll-desk
The following example clears the DNS cache:
#Clear the DNS cache.
PS C:\ > Clear-DNSClientCache
#Get a list of the host names currently in the cache
PS C:\> Get-DNSClientCache | Select-Object -Property Name
Get-DnsServerAddress
This cmdlet returns the DNS server addresses that the current machine is using to resolve host names. This cmdlet will return the loopback, IPv4, and IPv6 addresses that are being used. The name of the adapter is also included.
Usage examples
The following example returns the names and addresses of the DNS servers that are currently being utilized by the local machine:

DNSGlobalSettings
These cmdlets are used to enumerate and modify the global DNS settings for the local or remote DNS client. Some of the settings include root suffixes and whether to append parent suffixes.
Usage examples
The following example returns a list of the current DNS global settings for the local machine:
PS C:\> Get-DNSClientGlobalSetting
UseSuffixSearchList : True
SuffixSearchList : {mdn.ard}
UseDevolution : True
DevolutionLevel : 0
The following example replaces the DNS suffix search list with mdnvdi:
PS C:\> Set-DNSClientGlobalSetting -SuffixSearchList {"mdnvdi" }
Storage module
This is available in Windows 8 and Windows Server 2012 and it requires no features. There are a total of 64 cmdlets in this module:
PS C:\> Import-Module Storage
The storage module exposes all kinds of cmdlets for managing storage devices on a machine. Some of the resources that can be managed include physical and virtual disks, volumes, and partitions. In addition to managing physical or virtual storage resources, the module can manage the storage subsystem, pools, and providers. The cmdlets in this module are based on a CIM provider and can utilize CIM sessions.
Disk
These cmdlets manage both physical and virtual disks. In addition to enumerating and setting properties of existing disks, there are cmdlets for initializing disks with boot sectors.
Usage examples
The following example returns the disks on the local machine:
PS C:\ > Get-Disk
Number Friendly Name OperationalStatus Total Size Partition
------ ------------- ----------------- ---------- -----------
0 Virtual ... Online 127 GB MBR
1 Msft ... Online 200 MB MBR
The following example sets disk number 1 to offline and returns the result using Get-Disk:
PS C:\Users\Administrator> set-disk -Number 1 -IsOffline $true
PS C:\Users\Administrator> Get-Disk -Number 1
Number Friendly Name OperationalStatus Total Size Partition
------ ------------- ----------------- ---------- ---------
1 Msft ... Offline 200 MB MBR
The following example initializes disk number 1 with the Master Boot Record partition style:
PS C:\> Initialize-Disk -Number 1 -PartitionStyle MBR
Partition
These cmdlets manage disk partitions. It is possible to enumerate, modify, create, remove, and even resize partitions.
Usage examples
The following example creates a new partition on virtual disk number 1. This will create a new partition but will not format it. It will assign the driver letter D to the disk:
PS C:\> New-Partition –DiskNumber 1 –DriveLetter D
Disk Number: 1
Number DriveLetter Offset TotalSize Type
------ ----------- ------ --------- ----
2 D 33619968 67.88 MB Basic
The following example resizes an existing partition on disk number 1 to 50 MB:
PS C:\ > Resize-Partition -DiskNumber 1 -Number 2 -Size 50MB
PS C:\ > Get-Partition -DiskNumber 1
Disk Number: 1
Number DriveLetter Offset TotalSize Type
------ ----------- ------ --------- ----
1 17408 32 MB Reserved
2 D 33619968 50 MB Basic
Volume
These cmdlets deal with disk volumes. This set of cmdlets can enumerate volumes, format and repair volumes and even optimize volumes.
Usage examples
The following example gets a list of the volumes and displays their drive letter, description, and size:
PS C:\ > Get-Volume | Select-Object
-Property DriveLetter,FileSystemLabel ,Size
DriveLetter FileSystemLabel Size
----------- --------------- ----
System Reserved 366997504
C 135994011648
A 0
D 0
The following example formats an unallocated partition on a virtual disk. The default file system format is NTFS:

Roles and feature based modules
These modules are available for specified roles and features of the Windows 8 and Windows Server 2012 operating systems. They are not available to users who install the Windows Management Framework outside of these operating systems. Many of these modules require that a role or feature be installed. Several will not even be available until the role or feature is installed.
Hyper-V module
This module requires Hyper-V role, and it is imported using the following command:
PS C:\> Import-Module Hyper-V
Hyper-V is Microsoft's virtualization platform. It is a type 1 hypervisor and comes packaged as a configurable role in both Windows 8 and Windows Server 2012. Although this role was available in previous versions of the Windows Server family of operating systems, this is the first version to offer native PowerShell support, as well as run on the client version of the operating system. This module will not be available until the role is enabled.
VM
These cmdlets are used to directly work with virtual machines. The set includes cmdlets to start, stop, snapshot, and enumerate virtual machines on local and remote systems. These cmdlets are often paired with other virtual hardware cmdlets that allow for even finer grained management of virtual systems.
Usage examples
The following example shuts down all machines on the local server. The Stop-VM cmdlet can also power off machines;
PS C:\> Get-VM | Stop-VM –PassThru | Select-Object –Properties Name,State,Status
Name State Status
---- ----- ------
win7x6401 Off Operating normally
windows7 Off Operating normally
The following example shows how to create a new virtual machine. The newly created virtual machine will have one gigabyte of virtual memory, a 50 GB virtual hard disk and be named win7x6401. The virtual machine will also have several other hardware components added by default, such as a DVD drive:
PS C:\> New-vm -Name win7x6401 -MemoryStartupBytes 1GB
-NewVHDSize 50GB -NewVHDPath C:\vhd\win7x6401.
Vhdx | Select-Object –Properties Name,State,Status
Name State Status
---- ----- ------
win7x6401 Off Operating normally
The following example takes a snapshot of the current state of the virtual machine. It then returns a list of the snapshots for the virtual machine:
PS C:\ > Get-VM -Name win7x6401 | Checkpoint-VM
PS C:\ > Get-VM -Name win7x6401| Get-VMSnapshot | Select-Object -Property Name
Name
----
win7x6401 - (2/26/2012 - 9:54:25 AM)
VMDvdDrive, VMHardDiskDrive, and VMNetworkAdapter
These cmdlets manage virtual hardware for virtual machines. They are typically coupled with the Get-VM cmdlet. This list is not complete. There are several other cmdlets that can manage additional hardware, such as processors, COM ports, and even the BIOS. Most cmdlets that attempt to modify an existing virtual machine will require that the machine is not running.
Usage examples
The following example removes the virtual DVD drive from the virtual machine win7x6401:
PS C:\> Get-VM win7x6401 | Get-VMDvdDrive | Remove-VMDvdDrive –Verbose
VERBOSE: Remove-VMDvdDrive will remove DVD Drive on
IDE controller number 0 at location 1 from the virtual machine
"win7x6401".
The following example adds a new network adapter to the virtual machine "win7x6401."
PS C:\> Get-VM win7x6401 | Add-VMNetworkAdapter –Verbose
VERBOSE: Current VMobject = Microsoft.HyperV.PowerShell.VirtualMachine[]
VERBOSE: Add-VMNetworkAdapter will add a network adapter to
virtual machine "win7x6401".
Measure-VM
This cmdlet paired with Enable-VMResourceMetering, returns the historical resource usage for the virtual machine provided. This can be useful for tracking down troublesome, high-usage memory or processor time virtual machines.
Usage examples
The following example enables resource metering for the virtual machine windows7:
PS C:\ > Enable-VMResourceMetering –VMName windows7
The following example retrieves a snapshot of the resource usage for the virtual machine windows7:

VMHost
These cmdlets are used for managing Hyper-V host settings. Some of these settings include the MAC address range and the default path to store virtual machines and VHD files.
Usage examples
The following example sets the local host's resource metering save interval to two hours and the default virtual hard disk path to C:\VHDS:
PS C:\> Set-VMhost -ResourceMeteringSaveInterval
(New-TimeSpan -Hours 2) -VirtualHardDiskPath C:\VHDS
The following example returns the current settings for the local virtual machine host:

Active Directory deployment module
This module is available in Windows Server 2012 and it requires Active Directory Domain Services role. It has a total of 73 cmdlets. The following command shows how to import the module:
PS C:\> Import-Module ADDSDeployment
The Active Directory deployment module is used for installing and configuring Active Directory components such as domain controllers. In Windows Server 2012, Microsoft has deprecated the DCPromo.exe command line tool that has historically been used to perform the operations found in this module. In addition to installation, the module comes with numerous cmdlets for testing various aspects of an ADDS configuration.
Install-ADDSForest
These cmdlets are used to install a domain forest.
Usage examples
The following example installs a forest with the domain name MDN.ARD with a domain and forest mode of 2008 R2. Once the forest has been installed, the machine will be rebooted:
PS C:\> Install-ADDSForest –DomainName MDN.ARD
–DomainMode Win2008R2 –ForestMode Win2008R2 –RebootOnCompletion
ADDSDomainController
These cmdlets are used to promote and demote servers to and from domain controller status.
Usage examples
The following example promotes the current machine to a domain controller in the domain MDN.ARD:
PS C:\> Install-ADDSDomainController –DomainName MDN.ARD
cmdlet Install-ADDSDomainController at command pipeline position 1
Supply values for the following parameters:
SafeModeAdministratorPassword: ************
The following example demotes the last domain controller in a domain and removes the application partitions associated with it. The machine will restart once this is complete:
PS C:\ > Uninstall-ADDSDomainController
-LastDomainControllerInDomain -RemoveApplicationPartitions
cmdlet Uninstall-ADDSDomainController at command pipeline position 1
Supply values for the following parameters:
LocalAdministratorPassword: ****
Test ADDSDeployment
These cmdlets test all kinds of pieces of the ADDS deployment scenario. Some of the configuration aspects that can be tested include credential validity, NetBIOS names, and even available disk space. Many of these cmdlets are run as a part of the validation steps for some of the previously mentioned cmdlets.
Usage examples
The following example shows how we can use one of the test cmdlets to verify the status of a demote operation:
PS C:\ > Test-ADDSDomainControllerUninstallation
| Select-Object -ExpandProperty message
You indicated that this Active Directory domain controller
is not the last domain controller for the domain "mdn.ard".
However, no other domain controller for that domain can be contacted.
Proceeding will cause any Active Directory Domain Services changes that have been made on this domain
controller to be lost. To proceed anyway, set the 'IgnoreIsLast DCInDomainMismatch' option to 'YES'.
AppX module
This module is available in Windows 8 and Windows Server 2012 and it requires no role or feature. It has a total of five cmdlets:
PS C:\> Import-Module AppX
AppX is a new type of application packaging and deployment model that is part of Windows 8 and Windows Server 2012. Applications are packed with an application manifest file that defines metadata about the application. This metadata includes properties such as the name and copyright information, the dependencies, and the OS extensions that the application includes. The cmdlets in this module are designed to enumerate and deploy AppX packages. The cmdlets are not based on a CIM provider and do not offer a CIM session. The cmdlets also do not offer a ComputerName parameter and are intended to be run locally. To run remotely, we will have to use PowerShell remoting.
AppXPackage
These cmdlets can add, enumerate, and remove existing AppX packages from the local system.
Usage examples
The following example returns a list of the AppX packages currently installed on the local system:
PS C:\> Get-AppXPackage
Name : windows.immersivecontrolpanel
Publisher : CN=Microsoft Windows, O=Microsoft Corporation,
L=Redmond, S=Washington, C=US
Architecture :Neutral
ResourceId :
Version : 6.2.0.0
PackageFullName : windows.immersivecontrolpanel_6.2.0.0_neutral_neutral_cw5n1h2txyewy
InstallLocation : C:\Windows\System32\ImmersiveControlPanel
IsFramework : False
PackageUserInformation : {}
The following example removes an AppX package using the WhatIf parameter:
PS C:\Users\Administrator> remove-appxpackage
-Package "windows.Immersivecontrolpanel" –whatif
What if: Performing operation "Remove package" on Target "windows.Immersivecontrolpanel".
Get-AppXPackageManifest
This cmdlet returns the AppX package manifest as an XML document.
Usage examples
The following example returns the AppX package manifest for the Windows. ImmersiveControlPanel as an XML string:
PS C:\> Get-AppXPackageManifest –Package
"windows.Immersivecontrolpanel" | Select-Object –Property OuterXml
OuterXml
--------
PS C:\> Import-Module RemoteDesktop
Remote Desktop management module
The Remote Desktop management module exposes cmdlets for work with the remote desktop components found in Windows. The cmdlets include sets for working with pooled session hosts, virtual desktops, and working with brokered resources such as RemoteApps and remote desktops. This module can also configure roles, such as the Web Access and Gateway. Although the cmdlet does not require the Remote Desktop Services role to be installed, it requires access to an RDS-enabled server to manage.
BranchCache module
This module is available in Windows 8 and Windows Server 2012 and it requires BranchCache feature. It includes a total of 31 cmdlets. The following command is used to import this module:
PS C:\> Import-Module BranchCache
BranchCache is a Windows server and client feature that caches files locally that are stored on a remote, central location. As the BranchCache name implies, files are typically stored within a central headquarters while the outlying branches would consume them through network shares. Because of the limited bandwidth and high latency often found in WAN networks, BranchCache aims to limit this impact on shared file access. BranchCache works through both a hosted model, where a single server is the local cache and a peer-to-peer model, where clients themselves cache files and serve them to other clients. BranchCache has been available since Windows 7 and Server 2008 R2.
Once configured, the distribution server that hosts the BranchCache-enabled shares can be accessed by clients that have BranchCache enabled locally. Files within shares that have enabled BranchCache will have hashes calculated and published, so that client machines can easily identify files without downloading them. There are numerous new cmdlets found in this module to view the status of BranchCache, disable the system, or publish the file hashes for machines to consume.
Windows Update Services module
This module is available in Windows Server 2012 and it requires Windows Server Update Services feature. It includes a total of 13 cmdlets. The following command is used to import this module:
PS C:\> Import-Module UpdateServices
The Windows Update Services (WSUS) Module is used to manage a Windows update server. The cmdlets in this module can retrieve computers, updates, and products managed by WSUS. It is possible to enable product updating in WSUS through the use of these cmdlets as well.
Summary
In this article we looked at some of the new modules available in Windows 8 and Windows Server 2012. We saw through some simple examples, how to use some of the notable cmdlets in each one of the modules that are for more general use, and some of the more specific modules for particular roles that are enabled for the operating system.
The number of PowerShell cmdlets and modules in the new version of the Windows Management Framework and Windows operating systems is staggering. As we move forward with the adoption of the next version of these technologies, it will become necessary to have some knowledge of the capabilities that are built into the system and understand how to learn more about the functionality we have at our fingertips. Harnessing the strength that PowerShell offers will make us better administrators by reducing the need for manual interactions with an ever growing ecosystem of computer infrastructure.
Resources for Article :
Further resources on this subject:
- Using the Windows Azure Platform PowerShell Cmdlets [Article]
- Exchange Server 2010 Windows PowerShell: Managing Mailboxes [Article]
- Exchange Server 2010 Windows PowerShell: Working with Distribution Groups [Article]
- Exchange Server 2010 Windows PowerShell: Working with Address Lists [Article]



Post new comment