Skip to content

Instantly share code, notes, and snippets.

@pvanderwoude
Last active January 9, 2019 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvanderwoude/2bca050e6173809b86f95415c9f2cb47 to your computer and use it in GitHub Desktop.
Save pvanderwoude/2bca050e6173809b86f95415c9f2cb47 to your computer and use it in GitHub Desktop.
<#
.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