Skip to content

Instantly share code, notes, and snippets.

@pvanderwoude
Last active January 9, 2019 20:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
<#
.SYNOPSIS
Enable Windows Sandbox.
.DESCRIPTION
This script will simply enable the Windows Sandbox for the user.
.NOTES
Author: Peter van der Woude
Contact: pvanderwoude@hotmail.com
Date published: 07-01-2019
Current version: 1.0
.LINK
http://www.petervanderwoude.nl
.EXAMPLE
Enable-WindowsSandbox.ps1
#>
#Set variables as input for the script
$WindowsFeature = "Containers-DisposableClientVM"
try {
#Get the state of the Windows Feature
$WindowsFeatureState = (Get-WindowsOptionalFeature -FeatureName $WindowsFeature -Online).State
}
catch {
Write-Error "Failed to get the state of $WindowsFeature"
}
#Verify if the Windows Feature is enabled
if($WindowsFeatureState -eq "Enabled") {
Write-Output "$WindowsFeature is enabled"
}
else {
try {
#Enable the Windows Feature
Enable-WindowsOptionalFeature -FeatureName $WindowsFeature -Online -NoRestart -ErrorAction Stop
Write-Output "Successfully enabled $WindowsFeature"
}
catch {
Write-Error "Failed to enable $WindowsFeature"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment