Skip to main content

Mission possible with Windows PowerShell

Applies to: Windows 8, Windows 8.1

In Windows 8.1 the number of tasks you can perform using Windows PowerShell has increased. So, let’s take a look at some of the new, improved, or just plain fun functions you can perform using Windows PowerShell.

Mission 1: replace Diskpart.exe

In Windows 8, it was possible to use Windows PowerShell as a replacement for DISM.exe, but capturing and applying was missing. This has now been fixed and we can now use the Expand-WindowsImage cmdlet and the Add-WindowsImage cmdlets.

#To capture a disk as a wim:
Add-WindowsImage -ImagePath c:\imagestore\custom.wim -CapturePath d:\ -Name "The D Drive"

#To apply a Wimfile to a disk
Expand-WindowsImage -ImagePath c:\imagestore\custom.wim -Index 1 -ApplyPath e:\

Mission 2: export and import the Start screen

Sometimes it is necessary to modify the Start screen. The way to do this in previous versions of Windows was not that easy and that has changed with Windows 8.1. We can now use Export-StartLayout and Import-StartLayout. In this example, I’m importing the Start screen layout directly into the running operating sytem, but it could also be imported into a mounted image, just point –MountPath to the correct drive.

#Export the StartLayout
New-Item -Path c:\StartScreen -Type Directory -ErrorAction SilentlyContinue Export-StartLayout -Path c:\StartScreen\StartScreen.BIN -As BIN

#Import the StartLayout
Import-StartLayout -LayoutPath C:\StartScreen\StartScreen.BIN -MountPath C:\

Mission 3: download and deploy Windows PowerShell help

The help in Windows PowerShell is a bit better if you update it, but instead of updating every machine directly from the Internet, you can download the help files to a folder and then import them. This way, it is unnecessary for every person to download their own copy.

#Save Help in C:\Help
New-Item -Path C:\Help -ItemType Directory
Save-Help -DestinationPath c:\help –Verbose

#Update Help from C:\Help
Update-Help -SourcePath C:\help

Mission 4: put that configuration on that PC

One of the coolest new features is Desired State Configuration, which basically means that we can define how a Windows computer should be configured. We can use Desired State Configuration to install an application or a server fully configured as a web server, the possibilities are more or less unlimited. In this example, I need to install RDCMan on a Windows 8.1 computer, but the problem is that I really need to have .NET Framework 3 installed, since that is required for RDCman to be installed and working.

The script is divided into three parts; first, we define what we need and what part is depending on what; second, we generate the configuration including a .MOF file; and third, we execute the Desired State against the target using the Configuration cmdlet.

Configuration StandardConfig {
#Settings for Remote Desktop Connection Manager
Package RDCMan
Ensure = "Present"
Path = "$Env:SystemDrive\Install\RDCMan.msi"
Name = "RDCMan"
ProductId = "173A2B7F-535A-4403-A454-B41531EF0D7F"
DependsOn = "[Script]NetFX3"
#Settings for .Net Framework
Script NetFX3
SetScript =
Enable-WindowsOptionalFeature -FeatureName NetFx3 -Online -NoRestart
TestScript =
$NetFx3State = Get-WindowsOptionalFeature -FeatureName NetFx3 -Online If($NetFx3State.state -Like "Enabled"){Return $True}else{Return $False}
GetScript =
$NetFx3State = Get-WindowsOptionalFeature -FeatureName NetFx3 -Online
#Execute the Configuration Function StandardConfig
Start-DscConfiguration -Wait -Verbose -Path .\StandardConfig

Mission 5: test connectivity not using Ping.exe

I have been using ping like everyone else, but with Windows PowerShell you can switch over to something a bit more interesting. Using the Test-Connection cmdlet, you can now very easily use the information that gets returned back as a verification. Let’s assume that I would like to test the connectivity to a Microsoft web server. Using ping behind a normal firewall, this would not work. Using Test-Connection; however, will work since I can define how it should test it, in this case, using HTTP:

Test-NetConnection -InformationLevel Detailed -CommonTCPPort HTTP -Verbose

And the reply back will be:

Mission 6: we need Kiosk Mode

Kiosk Mode is a new feature in Windows 8.1 and of course there are some nice Windows PowerShell commands available to utilize it. We can assign applications to the user, as well as clear and get the assigned applications. First, we run need to find out what applications the user has currently. This means we need to log on with that account once to get all the application provisioned correctly; this can be done in a task sequence if needed. Then, we assign the application to the user and verify it. Suddenly, it is fun to build the kiosk computer using an automated deployment process to the lobby. :-)

#Get the AppPackage for the user Get-AppxPackage -User KioskUser | select Name

#Assign an Application to that user Set-AssignedAccess -AppName Microsoft.BingSports -UserName KioskUser

#Verify result

The result after running the command:

There are many other missions you can achieve; these are just a sample. I recommend that you download the latest version of Windows PowerShell (Windows PowerShell 4.0) today and see Scripting with Windows PowerShell for more details.

Additional resources

About the author

Mikael Nystrom is a Microsoft MVP and Microsoft Certified Trainer (MCT) specializing in deployment, virtualization, and management. He has been involved in Technology Adoption Programs (TAPs) for several Microsoft products and technologies including Windows Server, Hyper-V, and Windows 7. In addition to his work as a speaker, trainer, and consultant, Mikael frequently shares technical news and insights through his blog and on Twitter.