Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.