diff --git a/License.txt b/License.txt index 51163e5..9bb161e 100644 Binary files a/License.txt and b/License.txt differ diff --git a/WindowsSandboxTools.psd1 b/WindowsSandboxTools.psd1 index 92d51b7..2b208ba 100644 Binary files a/WindowsSandboxTools.psd1 and b/WindowsSandboxTools.psd1 differ diff --git a/changelog.md b/changelog.md index 21f8f32..0dc8ab8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,18 @@ # Change Log for Windows SandBox Tools +## v1.1.0 + +### Changed + +- Updated license. +- General code cleanup. +- Updated help documentation. +- Modified `Get-WSBConfiguration` to accept paths from the pipeline. + +### Added + +- Added missing online help links + ## v1.0.0 + Updated `Start-WindowsSandbox` to not scale resolutions. diff --git a/docs/Export-WsbConfiguration.md b/docs/Export-WsbConfiguration.md index b8e94fe..9e64728 100644 --- a/docs/Export-WsbConfiguration.md +++ b/docs/Export-WsbConfiguration.md @@ -1,7 +1,7 @@ --- external help file: WindowsSandboxTools-help.xml Module Name: WindowsSandboxTools -online version: +online version: https://bit.ly/3PkXMvl schema: 2.0.0 --- diff --git a/docs/Get-WsbConfiguration.md b/docs/Get-WsbConfiguration.md index 7f13929..0625266 100644 --- a/docs/Get-WsbConfiguration.md +++ b/docs/Get-WsbConfiguration.md @@ -1,7 +1,7 @@ --- external help file: WindowsSandboxTools-help.xml Module Name: WindowsSandboxTools -online version: +online version: https://bit.ly/44aWC9X schema: 2.0.0 --- @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -Get a Windows Sandbox configuratoin. +Get a Windows Sandbox configuration. ## SYNTAX @@ -83,7 +83,7 @@ Aliases: Required: True Position: 0 Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` diff --git a/docs/New-WsbConfiguration.md b/docs/New-WsbConfiguration.md index eb2c6a1..4462230 100644 --- a/docs/New-WsbConfiguration.md +++ b/docs/New-WsbConfiguration.md @@ -1,7 +1,7 @@ --- external help file: WindowsSandboxTools-help.xml Module Name: WindowsSandboxTools -online version: +online version: https://bit.ly/3qSqCJA schema: 2.0.0 --- @@ -279,4 +279,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell [New-WsbMappedFolder](New-WsbMappedFolder.md) -[Export-WsbConfiguration](Export-WsbConfiguration.md) \ No newline at end of file +[Export-WsbConfiguration](Export-WsbConfiguration.md) diff --git a/docs/New-WsbMappedFolder.md b/docs/New-WsbMappedFolder.md index d03ab60..ff4c0ee 100644 --- a/docs/New-WsbMappedFolder.md +++ b/docs/New-WsbMappedFolder.md @@ -1,7 +1,7 @@ --- external help file: WindowsSandboxTools-help.xml Module Name: WindowsSandboxTools -online version: +online version: https://bit.ly/3PkPqUH schema: 2.0.0 --- diff --git a/docs/Start-WindowsSandbox.md b/docs/Start-WindowsSandbox.md index 1478a43..e54d756 100644 --- a/docs/Start-WindowsSandbox.md +++ b/docs/Start-WindowsSandbox.md @@ -1,7 +1,7 @@ --- external help file: WindowsSandboxTools-help.xml Module Name: WindowsSandboxTools -online version: +online version: https://bit.ly/42Wde4i schema: 2.0.0 --- diff --git a/en-us/WindowsSandboxTools-help.xml b/en-us/WindowsSandboxTools-help.xml index ab145e8..22076f2 100644 --- a/en-us/WindowsSandboxTools-help.xml +++ b/en-us/WindowsSandboxTools-help.xml @@ -171,6 +171,10 @@ + + Online Version: + https://bit.ly/3PkXMvl + New-WsbConfiguration @@ -183,7 +187,7 @@ Get WsbConfiguration - Get a Windows Sandbox configuratoin. + Get a Windows Sandbox configuration. @@ -192,7 +196,7 @@ Get-WsbConfiguration - + Path Specify the path to the .wsb file. The command will autocomplete to the $wsbConfigPath variable. @@ -230,7 +234,7 @@ False - + Path Specify the path to the .wsb file. The command will autocomplete to the $wsbConfigPath variable. @@ -303,6 +307,10 @@ Jeff C:\scripts\wsbconfig\dev.wsb A test wsb file 12/10/2020 8:50:03 AM + + Online Version: + https://bit.ly/44aWC9X + New-WsbConfiguration @@ -904,6 +912,10 @@ Jeff C:\scripts\wsbconfig\dev.wsb A test wsb file 12/10/2020 8:50:03 AM + + Online Version: + https://bit.ly/3qSqCJA + New-WsbMappedFolder @@ -1040,6 +1052,10 @@ PS C:\> New-WsbConfiguration -Name work -MappedFolder $map -Description "Work + + Online Version: + https://bit.ly/3PkPqUH + New-WsbConfiguration @@ -1261,6 +1277,10 @@ PS C:\> New-WsbConfiguration -Name work -MappedFolder $map -Description "Work + + Online Version: + https://bit.ly/42Wde4i + Get-WsbConfiguration diff --git a/functions/Export-WsbConfiguration.ps1 b/functions/Export-WsbConfiguration.ps1 index 3c151cf..7230b63 100644 --- a/functions/Export-WsbConfiguration.ps1 +++ b/functions/Export-WsbConfiguration.ps1 @@ -1,20 +1,20 @@ function Export-WsbConfiguration { - [cmdletbinding(SupportsShouldProcess)] - [outputType([System.io.fileInfo])] + [CmdletBinding(SupportsShouldProcess)] + [OutputType([System.io.fileInfo])] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline, HelpMessage = "Specify a wsbConfiguration object.")] - [ValidateNotNullorEmpty()] + [ValidateNotNullOrEmpty()] [wsbConfiguration]$Configuration, [Parameter(Mandatory, HelpMessage = "Specify the path and filename. It must end in .wsb")] [ValidatePattern("\.wsb$")] #verify the parent path exists [ValidateScript( { Test-Path $(Split-Path $_ -Parent) })] - [string]$Path, + [String]$Path, [Parameter(HelpMessage = "Don't overwrite an existing file")] - [switch]$NoClobber + [Switch]$NoClobber ) Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN] Starting $($MyInvocation.MyCommand)" <# Convert the path to a valid FileSystem path. Normally, I would use Convert-Path but it will fail if the file doesn't exist. Instead, I'll split the path, convert @@ -25,16 +25,16 @@ function Export-WsbConfiguration { $cPath = Join-Path -Path $parent -ChildPath $leaf } #begin Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating an XML document" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating an XML document" $xml = New-Object System.Xml.XmlDocument $config = $xml.CreateElement("element", "Configuration", "") #add my custom metadata - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Inserting metadata" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Inserting metadata" $meta = $xml.CreateElement("element", "Metadata", "") $metaprops = "Name", "Author", "Description", "Updated" foreach ($prop in $metaprops) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ..$prop = $($configuration.Metadata.$prop)" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] ..$prop = $($configuration.Metadata.$prop)" $item = $xml.CreateElement($prop) $item.set_innertext($configuration.Metadata.$prop) [void]$meta.AppendChild($item) @@ -42,29 +42,29 @@ function Export-WsbConfiguration { [void]$config.AppendChild($meta) #add primary properties - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding primary data" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding primary data" $mainprops = "vGPU", "MemoryInMB", "AudioInput", "VideoInput", "ClipboardRedirection", "PrinterRedirection", "Networking", "ProtectedClient" foreach ($prop in $mainprops) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ..$prop = $($configuration.$prop)" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] ..$prop = $($configuration.$prop)" $item = $xml.CreateElement($prop) $item.set_innertext($configuration.$prop) [void]$config.AppendChild($item) } if ($Configuration.LogonCommand) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding a logon command" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding a logon command" $logon = $xml.CreateElement("element", "LogonCommand", "") $cmd = $xml.CreateElement("Command") - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ..$($configuration.LogonCommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] ..$($configuration.LogonCommand)" $cmd.set_innerText($configuration.LogonCommand) [void]$logon.AppendChild($cmd) [void]$config.AppendChild($logon) } if ($Configuration.MappedFolder) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding mapped folders" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding mapped folders" $mapped = $xml.CreateElement("element", "MappedFolders", "") foreach ($f in $Configuration.MappedFolder) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] $($f.HostFolder) -> $($f.SandboxFolder) [RO:$($f.ReadOnly)]" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] $($f.HostFolder) -> $($f.SandboxFolder) [RO:$($f.ReadOnly)]" $mf = $xml.CreateElement("element", "MappedFolder", "") "HostFolder", "SandboxFolder", "ReadOnly" | ForEach-Object { @@ -79,7 +79,7 @@ function Export-WsbConfiguration { [void]$xml.AppendChild($config) - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Exporting configuration to $cPath" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Exporting configuration to $cPath" if ($PSCmdlet.ShouldProcess($cpath)) { if ((Test-Path -Path $cPath) -AND $NoClobber) { Write-Warning "A file exists at $cPath and NoClobber was specified." @@ -87,10 +87,10 @@ function Export-WsbConfiguration { else { $xml.Save($cPath) } - } #whatif + } #WhatIf } #process End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #end } diff --git a/functions/Get-WsbConfiguration.ps1 b/functions/Get-WsbConfiguration.ps1 index b8d6e0c..22e459c 100644 --- a/functions/Get-WsbConfiguration.ps1 +++ b/functions/Get-WsbConfiguration.ps1 @@ -1,56 +1,72 @@ Function Get-WsbConfiguration { - [cmdletbinding()] - [outputType("wsbConfiguration")] + [CmdletBinding()] + [OutputType('wsbConfiguration')] Param( - [Parameter(Position = 0, Mandatory, HelpMessage = "Specify the path to the .wsb file.")] + [Parameter( + Position = 0, + Mandatory, + ValueFromPipeline, + HelpMessage = 'Specify the path to the .wsb file.' + )] [ValidatePattern('\.wsb$')] [ValidateScript( { Test-Path $_ })] - [ArgumentCompleter( { if (Test-Path $global:wsbConfigPath) { (Get-ChildItem $Global:wsbConfigPath).fullname } })] - [string]$Path, - [Parameter(HelpMessage = "Only display metadata information.")] - [switch]$MetadataOnly + [ArgumentCompleter( { if (Test-Path $global:wsbConfigPath) { (Get-ChildItem $Global:wsbConfigPath).FullName } })] + [String]$Path, + + [Parameter(HelpMessage = 'Only display metadata information.')] + [Switch]$MetadataOnly ) - $cPath = Convert-Path $Path - Write-Verbose "Getting configuration from $cPath" + Begin { + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" + } #begin + Process { + + $cPath = Convert-Path $Path + Write-Verbose "Getting configuration from $cPath" - [xml]$wsb = Get-Content -Path $cPath + [xml]$wsb = Get-Content -Path $cPath - Write-Verbose "Building property list" - $properties = [System.Collections.Generic.List[object]]::new() - $properties.AddRange($wsb.configuration.psadapted.psobject.properties.name) - if ($properties.Contains("LogonCommand")) { - [void]($properties.Remove("LogonCommand")) - $properties.Add(@{Name = "LogonCommand"; Expression = { $wsb.configuration.logonCommand.Command } }) - } - if ($properties.Contains("MappedFolders")) { - [void]($properties.Remove("MappedFolders")) - $properties.Add(@{Name = "MappedFolder"; Expression = { - $wsb.Configuration.MappedFolders.MappedFolder | - Select-Object *folder,@{Name="ReadOnly";Expression = { if ($_.ReadOnly -eq 'True') { $True } else {$False}}} | - New-WsbMappedFolder | New-WsbMappedFolder } }) - } + Write-Verbose 'Building property list' + $properties = [System.Collections.Generic.List[object]]::new() + $properties.AddRange($wsb.configuration.PSAdapted.PSObject.properties.name) + if ($properties.Contains('LogonCommand')) { + [void]($properties.Remove('LogonCommand')) + $properties.Add(@{Name = 'LogonCommand'; Expression = { $wsb.configuration.logonCommand.Command } }) + } + if ($properties.Contains('MappedFolders')) { + [void]($properties.Remove('MappedFolders')) + $properties.Add(@{Name = 'MappedFolder'; Expression = { + $wsb.Configuration.MappedFolders.MappedFolder | + Select-Object *folder, @{Name = 'ReadOnly'; Expression = { if ($_.ReadOnly -eq 'True') { $True } else { $False } } } | + New-WsbMappedFolder | New-WsbMappedFolder } + }) + } - Write-Verbose "Get metadata information" - if ($wsb.configuration.metadata) { - Write-Verbose "Existing metadata found" - $meta = [wsbMetadata]::new($wsb.Configuration.metadata.Name, $wsb.configuration.metadata.Description) - $meta.updated = $wsb.configuration.metadata.updated - $meta.author = $wsb.configuration.metadata.author - } - else { - Write-Verbose "Defining new metadata" - $meta = [wsbMetadata]::new($cPath) - $meta.updated = Get-Date - } + Write-Verbose 'Get metadata information' + if ($wsb.configuration.metadata) { + Write-Verbose 'Existing metadata found' + $meta = [wsbMetadata]::new($wsb.Configuration.metadata.Name, $wsb.configuration.metadata.Description) + $meta.updated = $wsb.configuration.metadata.updated + $meta.author = $wsb.configuration.metadata.author + } + else { + Write-Verbose 'Defining new metadata' + $meta = [wsbMetadata]::new($cPath) + $meta.updated = Get-Date + } - if ($MetadataOnly) { - Write-Verbose "Displaying metadata only" - $meta - } - else { - Write-Verbose "Sending configuration to New-WsbConfiguration" - $wsb.configuration | Select-Object -Property $properties | New-WsbConfiguration -metadata $meta - Write-Verbose "Ending $($myinvocation.mycommand)" - } + if ($MetadataOnly) { + Write-Verbose 'Displaying metadata only' + $meta + } + else { + Write-Verbose 'Sending configuration to New-WsbConfiguration' + $wsb.configuration | Select-Object -Property $properties | New-WsbConfiguration -metadata $meta + Write-Verbose "Ending $($MyInvocation.MyCommand)" + } + } #process + End { + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" + } #end } diff --git a/functions/New-WsbConfiguration.ps1 b/functions/New-WsbConfiguration.ps1 index 393ab63..8e462d6 100644 --- a/functions/New-WsbConfiguration.ps1 +++ b/functions/New-WsbConfiguration.ps1 @@ -1,38 +1,38 @@ Function New-WsbConfiguration { - [cmdletbinding(DefaultParameterSetName = "name")] - [outputType("wsbConfiguration")] + [CmdletBinding(DefaultParameterSetName = "name")] + [OutputType("wsbConfiguration")] Param( [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Enable", "Disable")] - [string]$vGPU = "Default", + [String]$vGPU = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateScript( { $_ -ge 1024 })] - [string]$MemoryInMB = 4096, + [String]$MemoryInMB = 4096, [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Enable", "Disable")] - [string]$AudioInput = "Default", + [String]$AudioInput = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Enable", "Disable")] - [string]$VideoInput = "Default", + [String]$VideoInput = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Disable")] - [string]$ClipboardRedirection = "Default", + [String]$ClipboardRedirection = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Enable", "Disable")] - [string]$PrinterRedirection = "Default", + [String]$PrinterRedirection = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Disable")] - [string]$Networking = "Default", + [String]$Networking = "Default", [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet("Default", "Enable", "Disable")] - [string]$ProtectedClient = "Default", + [String]$ProtectedClient = "Default", [Parameter(ValueFromPipelineByPropertyName, HelpMessage = "The path and file are relative to the Windows Sandbox")] [object]$LogonCommand, @@ -44,24 +44,24 @@ Function New-WsbConfiguration { [wsbMetadata]$Metadata, [parameter(Mandatory, ParameterSetName = "name", HelpMessage = "Give the configuration a name")] - [string]$Name, + [String]$Name, [parameter(ParameterSetName = "name", HelpMessage = "Provide a description")] - [string]$Description, + [String]$Description, [parameter(ParameterSetName = "name", HelpMessage = "Who is the author?")] - [string]$Author = $env:USERNAME + [String]$Author = $env:USERNAME ) Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN] Starting $($MyInvocation.MyCommand)" $new = [wsbConfiguration]::new() } #begin Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a configuration" - Write-Verbose ($psboundparameters | Out-String) + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating a configuration" + Write-Verbose ($PSBoundParameters | Out-String) - if ($logonCommand -is [string]) { + if ($logonCommand -is [String]) { $cmd = $LogonCommand } elseif ($logonCommand.Command) { @@ -89,12 +89,12 @@ Function New-WsbConfiguration { $metadata.updated = Get-Date } - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Setting metadata" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Setting metadata" $new.metadata = $metadata $new } #process End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #end } diff --git a/functions/New-WsbMappedFolder.ps1 b/functions/New-WsbMappedFolder.ps1 index 83bde77..8379dcc 100644 --- a/functions/New-WsbMappedFolder.ps1 +++ b/functions/New-WsbMappedFolder.ps1 @@ -1,30 +1,30 @@ Function New-WsbMappedFolder { - [cmdletbinding()] + [CmdletBinding()] [OutputType("wsbMappedFolder")] Param( [Parameter(Position = 0, Mandatory, ValueFromPipelineByPropertyName, HelpMessage = "Specify the path to the local folder you want to map.")] [ValidateScript( { Test-Path $_ })] - [string]$HostFolder, + [String]$HostFolder, [Parameter(Position = 1, Mandatory, ValueFromPipelineByPropertyName, HelpMessage = "Specify the mapped folder for the Windows Sandbox. It must start with C:\")] - [ValidateNotNullorEmpty()] + [ValidateNotNullOrEmpty()] [ValidatePattern('^C:\\')] - [string]$SandboxFolder, + [String]$SandboxFolder, [Parameter(ValueFromPipelineByPropertyName, HelpMessage = "Specify if you want the mapping to be Read-Only.")] #[ValidateSet("True", "False")] - [switch]$ReadOnly + [Switch]$ReadOnly ) Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN] Starting $($MyInvocation.MyCommand)" } #begin Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Processing" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Processing" [wsbMappedFolder]::New($HostFolder, $SandboxFolder, $ReadOnly) } #process End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #end } diff --git a/functions/Start-WindowsSandbox.ps1 b/functions/Start-WindowsSandbox.ps1 index 4062f80..8a9edd8 100644 --- a/functions/Start-WindowsSandbox.ps1 +++ b/functions/Start-WindowsSandbox.ps1 @@ -1,22 +1,22 @@ Function Start-WindowsSandbox { - [cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "config")] + [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "config")] [alias("wsb")] [OutputType("none")] Param( [Parameter(Position = 0, Mandatory, ParameterSetName = "config", HelpMessage = "Specify the path to a wsb file.")] [ValidateScript( { Test-Path $_ })] - [ArgumentCompleter( { if (Test-Path $global:wsbConfigPath) { (Get-ChildItem $Global:wsbConfigPath).fullname } })] - [string]$Configuration, + [ArgumentCompleter( { if (Test-Path $global:wsbConfigPath) { (Get-ChildItem $Global:wsbConfigPath).FullName } })] + [String]$Configuration, [Parameter(ParameterSetName = "normal", HelpMessage = "Start with no customizations.")] - [switch]$NoSetup, + [Switch]$NoSetup, [Parameter(HelpMessage = "Specify desktop resolutions as an array like 1280,720. The default is 1920,1080.")] [int[]]$WindowSize = @(1920, 1080) ) - Write-Verbose "[$((Get-Date).TimeOfDay)] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay)] Starting $($MyInvocation.MyCommand)" #test if Windows Sandbox is already running $test = Get-Process -ErrorAction SilentlyContinue -Name WindowsSandbox* @@ -27,7 +27,7 @@ Function Start-WindowsSandbox { } if ($NoSetup) { Write-Verbose "[$((Get-Date).TimeOfDay)] Launching default WindowsSandbox.exe" - if ($PSCmdlet.shouldProcess("default configuration", "Launch Windows Sandbox")) { + if ($PSCmdlet.ShouldProcess("default configuration", "Launch Windows Sandbox")) { Start-Process -FilePath $env:windir\system32\WindowsSandbox.exe } } @@ -48,14 +48,14 @@ Function Start-WindowsSandbox { [void](Register-Watcher) } - if ($PSCmdlet.shouldProcess($Configuration, "Launch Windows Sandbox")) { + if ($PSCmdlet.ShouldProcess($Configuration, "Launch Windows Sandbox")) { Start-Process -FilePath $Configuration } } #WindowsSandbox.exe launches a child process, WindowsSandboxClient. #That is the process that needs to be minimized - if ($pscmdlet.shouldProcess("WindowsSandboxClient", "Waiting for process")) { + if ($PSCmdlet.ShouldProcess("WindowsSandboxClient", "Waiting for process")) { Write-Verbose "[$((Get-Date).TimeOfDay)] Waiting for child process WindowsSandboxClient" do { @@ -67,12 +67,12 @@ Function Start-WindowsSandbox { } Write-Verbose "[$((Get-Date).TimeOfDay)] Setting Window size to $($WindowSize -join 'x')" - if ($pscmdlet.shouldProcess("WindowsSandboxClient", "Modifying Window size and state")) { + if ($PSCmdlet.ShouldProcess("WindowsSandboxClient", "Modifying Window size and state")) { $clientProc = Get-Process -Name WindowsSandboxClient #values to pass to the function are a percentage of the desired size #TODO: figure out scaling in display resolution set to scale - [int]$width = $WindowSize[0] #* .6667 - [int]$Height = $WindowSize[1] # * .6667 + [Int]$width = $WindowSize[0] #* .6667 + [Int]$Height = $WindowSize[1] # * .6667 Write-Verbose "[$((Get-Date).TimeOfDay)] Modifying handle $($clientproc.mainwindowhandle) with a width of $($WindowSize[0]) and height of $($WindowSize[1])" Set-WindowSize -handle $clientproc.MainWindowHandle -width $width -height $height @@ -93,7 +93,7 @@ Function Start-WindowsSandbox { $wsb.MappedFolder | Out-String | Write-Verbose } } - Write-Verbose "[$((Get-Date).TimeOfDay)] Ending $($myinvocation.mycommand)." + Write-Verbose "[$((Get-Date).TimeOfDay)] Ending $($MyInvocation.MyCommand)." Write-Host "[$((Get-Date).TimeOfDay)] Windows Sandbox has been launched. You may need to wait for any configurations to complete." -ForegroundColor green } diff --git a/functions/private.ps1 b/functions/private.ps1 index 3c17855..2d57a2b 100644 --- a/functions/private.ps1 +++ b/functions/private.ps1 @@ -2,7 +2,7 @@ Function Set-WindowSize { #from https://gist.github.com/coldnebo/1148334 - [cmdletbinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] Param( [Parameter( Position = 0, @@ -10,17 +10,17 @@ Function Set-WindowSize { ValueFromPipeline, ValueFromPipelineByPropertyName )] - [ValidateNotNullorEmpty()] + [ValidateNotNullOrEmpty()] [Alias("handle")] [System.IntPtr]$MainWindowHandle = (Get-Process -id $pid).MainWindowHandle, [Alias("x")] - [int]$Width = 1280, + [Int]$Width = 1280, [Alias("y")] - [int]$Height = 720 + [Int]$Height = 720 ) Begin { - Write-Verbose "Starting $($MyInvocation.Mycommand)" + Write-Verbose "Starting $($MyInvocation.MyCommand)" Write-Verbose "Using a window width of $Width" Write-Verbose "Using a window Height of $height" Write-Verbose "Adding type code" @@ -88,12 +88,12 @@ public struct RECT [void]([Win32]::MoveWindow($MainWindowHandle, 0, 0, $width + $dx, $height + $dy, $true )) - } #close Whatif + } #close WhatIf } #process End { - Write-Verbose "Ending $($MyInvocation.Mycommand)" + Write-Verbose "Ending $($MyInvocation.MyCommand)" } #end } #end Set-WindowSize function @@ -113,7 +113,7 @@ function Set-WindowState { [ValidateSet('FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE', 'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED', 'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL')] - [string] $State = 'SHOW' + [String] $State = 'SHOW' ) Begin { @@ -166,23 +166,23 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); } Function Register-Watcher { - [cmdletbinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] Param( [Parameter(HelpMessage = "Enter the full filename and path to the flag file. The file will be created in the sandbox in a shared folder.")] - [ValidateNotNullorEmpty()] - [string]$Flag = "C:\scripts\sandbox.flag", + [ValidateNotNullOrEmpty()] + [String]$Flag = "C:\scripts\sandbox.flag", [Parameter(HelpMessage = "Enter the title for the toast notification.")] - [string]$Title = "Windows Sandbox", + [String]$Title = "Windows Sandbox", [Parameter(HelpMessage = "Enter the path to an image file for the toast notification.")] [ValidateScript( { Test-Path $_ })] - [string]$Logo = "$PSScriptRoot\..\images\sandbox.jpg", + [String]$Logo = "$PSScriptRoot\..\images\sandbox.jpg", [Parameter(HelpMessage = "Specify the sound to play for the toast notification.")] [ValidateSet('Default', 'IM', 'Mail', 'Reminder', 'SMS', 'Alarm', 'Alarm2', 'Alarm3', 'Alarm4', 'Alarm5', 'Alarm6', 'Alarm7', 'Alarm8', 'Alarm9', 'Alarm10', 'Call', 'Call2', 'Call3', 'Call4', 'Call5', 'Call6', 'Call7', 'Call8', 'Call9', 'Call10', 'None' )] - [string]$Sound = "Call10" + [String]$Sound = "Call10" ) #the event subscriber identifier @@ -228,7 +228,7 @@ if (Test-Path $flag) { $action = [scriptblock]::Create($sb) - if ($pscmdlet.ShouldProcess($query, "Register Event")) { + if ($PSCmdlet.ShouldProcess($query, "Register Event")) { Register-CimIndicationEvent -query $query -source $SourceID -Action $action } #WhatIf -} \ No newline at end of file +} diff --git a/wsbScripts/Install-VSCodeSandbox.ps1 b/wsbScripts/Install-VSCodeSandbox.ps1 index 6482da1..8224533 100644 --- a/wsbScripts/Install-VSCodeSandbox.ps1 +++ b/wsbScripts/Install-VSCodeSandbox.ps1 @@ -23,7 +23,7 @@ $loadInf | Out-File $infPath Start-Process -FilePath $file -ArgumentList "/VERYSILENT /LOADINF=${infPath}" -Wait #add extensions -Start-Process -FilePath "C:\Program Files\Microsoft VS Code\bin\code.cmd" -ArgumentList "--install-extension ms-vscode.powerShell" +Start-Process -FilePath "C:\Program Files\Microsoft VS Code\bin\code.cmd" -ArgumentList "--install-extension ms-vscode.PowerShell" if (Test-Path Function:\log) { log "VSCode Setup Complete" diff --git a/wsbScripts/Set-SandboxDesktop.ps1 b/wsbScripts/Set-SandboxDesktop.ps1 index ab44979..c926489 100644 --- a/wsbScripts/Set-SandboxDesktop.ps1 +++ b/wsbScripts/Set-SandboxDesktop.ps1 @@ -2,12 +2,12 @@ # my Pluralsight-related configuration function Update-Wallpaper { - [cmdletbinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] Param( [Parameter(Position = 0, HelpMessage = "The path to the wallpaper file.")] [alias("wallpaper")] [ValidateScript( { Test-Path $_ })] - [string]$Path = $(Get-ItemPropertyValue -Path 'hkcu:\Control Panel\Desktop\' -Name Wallpaper) + [String]$Path = $(Get-ItemPropertyValue -Path 'hkcu:\Control Panel\Desktop\' -Name Wallpaper) ) Add-Type @" @@ -32,7 +32,7 @@ function Update-Wallpaper { } "@ - if ($PSCmdlet.shouldProcess($path)) { + if ($PSCmdlet.ShouldProcess($path)) { [Wallpaper.UpdateImage]::Refresh($Path) } } @@ -42,17 +42,17 @@ Function Restart-Explorer { .Synopsis Restart the Windows Explorer process. #> - [cmdletbinding(SupportsShouldProcess)] - [Outputtype("None")] + [CmdletBinding(SupportsShouldProcess)] + [OutputType("None")] Param() - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Stopping Explorer.exe process" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Stopping Explorer.exe process" Get-Process -Name Explorer | Stop-Process -Force #give the process time to start Start-Sleep -Seconds 2 Try { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Verifying Explorer restarted" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Verifying Explorer restarted" $p = Get-Process -Name Explorer -ErrorAction stop } Catch { @@ -65,7 +65,7 @@ Function Restart-Explorer { Throw $_ } } - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #configure the taskbar and hide icons @@ -106,4 +106,4 @@ Restart-Explorer if (Test-Path function:\log) { log "Desktop configuration complete" -} \ No newline at end of file +} diff --git a/wsbScripts/demo-config.ps1 b/wsbScripts/demo-config.ps1 index 1b14022..e431b49 100644 --- a/wsbScripts/demo-config.ps1 +++ b/wsbScripts/demo-config.ps1 @@ -5,7 +5,7 @@ $logParams = @{ Append = $True } -"[$(Get-Date)] Starting $($myinvocation.mycommand)" | Out-File @logParams +"[$(Get-Date)] Starting $($MyInvocation.MyCommand)" | Out-File @logParams "[$(Get-Date)] Enabling PSRemoting" | Out-File @logParams Enable-PSRemoting -Force -SkipNetworkProfileCheck diff --git a/wsbScripts/sandbox-config-pluralsight.ps1 b/wsbScripts/sandbox-config-pluralsight.ps1 index c0873e2..b5974a4 100644 --- a/wsbScripts/sandbox-config-pluralsight.ps1 +++ b/wsbScripts/sandbox-config-pluralsight.ps1 @@ -5,8 +5,8 @@ $SetupPath = "C:\scripts\wsbScripts" #create a log file of the configuration process. Function log { Param( - [string]$msg, - [string]$log = "C:\work\wsblog.txt" + [String]$msg, + [String]$log = "C:\work\wsblog.txt" ) "[{0}] {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Encoding ascii -Append @@ -16,17 +16,17 @@ log "Install package provider" Install-PackageProvider -name nuget -force -forcebootstrap -scope allusers log "Updating package management" -Install-Module PackageManagement, PowerShellGet, PSReadline, WTToolbox -Force +Install-Module PackageManagement, PowerShellGet, PSReadLine, WTToolbox -Force #run updates and installs in the background log "Updating Windows PowerShell Help" -Start-Job { powershell -command { Update-Help -Force } } +Start-Job { PowerShell -command { Update-Help -Force } } log "Installing default modules: PSScriptTools, PSTeachingTools, BurntToast" Start-Job { Install-Module PSScriptTools, PSTeachingTools, BurntToast -Force } log "Installing PSReleaseTools and PowerShell 7.x" Start-Job { - $msi = (Get-Item C:\shared\Powershell-7.1*msi).fullname - Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1" -Wait + $msi = (Get-Item C:\shared\PowerShell-7.1*msi).FullName + Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPowerShell=1 ADD_FILE_CONTEXT_MENU_RUNPowerShell=1" -Wait #update help C:\Program` Files\PowerShell\7\pwsh.exe -command { Update-Help -Force } @@ -95,8 +95,8 @@ Start-Job { Get-ChildItem -Path $Fontsource -File | ForEach-Object { #Write-Host "Testing $($_.name)" if ($installedFiles -notcontains $_.name) { - Write-Host "installing $($_.name) from $($_.fullname)" -ForegroundColor green - $fontFolder.copyHere($_.fullname) + Write-Host "installing $($_.name) from $($_.FullName)" -ForegroundColor green + $fontFolder.copyHere($_.FullName) } else { Write-Host "$($_.name) already installed" -ForegroundColor yellow diff --git a/wsbScripts/sandbox-config-presentation.ps1 b/wsbScripts/sandbox-config-presentation.ps1 index 1cafe5e..9b95eb4 100644 --- a/wsbScripts/sandbox-config-presentation.ps1 +++ b/wsbScripts/sandbox-config-presentation.ps1 @@ -5,8 +5,8 @@ $SetupPath = "C:\scripts\wsbScripts" #create a log file of the configuration process. Function log { Param( - [string]$msg, - [string]$log = "C:\work\wsblog.txt" + [String]$msg, + [String]$log = "C:\work\wsblog.txt" ) "[{0}] {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Encoding ascii -Append @@ -17,7 +17,7 @@ Install-Module PackageManagement, PowerShellGet -Force #run updates and installs in the background log "Updating Windows PowerShell Help" -Start-Job { powershell -command { Update-Help -Force } } +Start-Job { PowerShell -command { Update-Help -Force } } log "Installing default modules: PSScriptTools, PSTypeExtensionTools,PSTeachingTools, BurntToast" Start-Job { Install-Module PSScriptTools, PSTeachingTools, PSTypeExtensionTools, BurntToast -Force } log "Installing PSReleaseTools and PowerShell 7 + Preview" @@ -41,8 +41,8 @@ log "Installing Applications" Start-Job { Function log { Param( - [string]$msg, - [string]$log = "C:\work\wsblog.txt" + [String]$msg, + [String]$log = "C:\work\wsblog.txt" ) "[{0}] {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Encoding ascii -Append @@ -55,9 +55,9 @@ Start-Job { log "Installing VSCode" winget install Microsoft.visualStudioCode log "Configuring VSCode" - &'C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' --install-extension ms-vscode.powershell + &'C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' --install-extension ms-vscode.PowerShell &'C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' --install-extension CoenraadS.bracket-pair-colorizer-2 - &'C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' --install-extension TylerLeonhardt.vscode-inline-values-powershell + &'C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' --install-extension TylerLeonhardt.vscode-inline-values-PowerShell Copy-item -path C:\shared\vscode-settings.json -Destination "c:\Users\WDAGUtilityAccount\AppData\Roaming\Code\User\settings.json" Log "Installing Edge" diff --git a/wsbScripts/sandbox-config.ps1 b/wsbScripts/sandbox-config.ps1 index f66dfc6..c6dd2d4 100644 --- a/wsbScripts/sandbox-config.ps1 +++ b/wsbScripts/sandbox-config.ps1 @@ -5,8 +5,8 @@ $SetupPath = "C:\scripts\wsbScripts" #create a log file of the configuration process. Function log { Param( - [string]$msg, - [string]$log = "C:\work\wsblog.txt" + [String]$msg, + [String]$log = "C:\work\wsblog.txt" ) "[{0}] {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Encoding ascii -Append @@ -16,8 +16,8 @@ Function log { $init = { Function log { Param( - [string]$msg, - [string]$log = "C:\work\wsblog.txt" + [String]$msg, + [String]$log = "C:\work\wsblog.txt" ) "[{0}] {1}" -f (Get-Date), $msg | Out-File -FilePath $log -Encoding ascii -Append @@ -28,7 +28,7 @@ $init = { $jobparams = @{InitializationScript = $init} $begin = Get-Date -log "Starting Windows Sandbox configuration $($myinvocation.MyCommand)" +log "Starting Windows Sandbox configuration $($MyInvocation.MyCommand)" log "Enabling PowerShell remoting" Enable-PSRemoting -Force -SkipNetworkProfileCheck @@ -36,7 +36,7 @@ log "Install package provider" Install-PackageProvider -name nuget -force -forcebootstrap -scope allusers log "Updating package management" -Install-Module PackageManagement, PowerShellGet,PSReadline -Force +Install-Module PackageManagement, PowerShellGet,PSReadLine -Force #run updates and installs in the background log "Setting DNS server to 1.1.1.1" @@ -46,7 +46,7 @@ log "Installing VSCode" Start-Job -name VSCode -FilePath (Join-Path -Path $SetupPath -ChildPath Install-vscodesandbox.ps1) @jobparams log "Updating Windows PowerShell Help" -#Start-Job -ScriptBlock { powershell -command { Update-Help -Force } ; log "Help updated" } @jobparams +#Start-Job -ScriptBlock { PowerShell -command { Update-Help -Force } ; log "Help updated" } @jobparams Start-Job -name "Help-Update" -ScriptBlock { Update-Help -Force ; log "Help updated" } @jobparams log "Installing default modules: PSScriptTools, PSTeachingTools, BurntToast" @@ -57,10 +57,10 @@ Start-Job -name "Module-Install" -ScriptBlock { log "Installing PSReleaseTools and PowerShell 7 + Preview" Start-Job -name "PS7-Install" -ScriptBlock { Install-Module PSReleaseTools -Force - $msi = (Get-Item C:\shared\Powershell-7.1*.msi).fullname - Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1" - $msi = (Get-Item C:\shared\Powershell-7*preview*.msi).fullname - Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1" + $msi = (Get-Item C:\shared\PowerShell-7.1*.msi).FullName + Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPowerShell=1 ADD_FILE_CONTEXT_MENU_RUNPowerShell=1" + $msi = (Get-Item C:\shared\PowerShell-7*preview*.msi).FullName + Start-Process -FilePath $msi -ArgumentList "/quiet REGISTER_MANIFEST=1 ADD_PATH=1 ENABLE_PSREMOTING=1 ADD_EXPLORER_CONTEXT_MENU_OPENPowerShell=1 ADD_FILE_CONTEXT_MENU_RUNPowerShell=1" #Install-PowerShell -Mode quiet -EnableRemoting -EnableContextMenu #Install-PSPreview -Mode quiet -EnableRemoting -EnableContextMenu @@ -88,7 +88,7 @@ log "Waiting for background jobs to complete" Get-Job | Wait-Job #add jobs to the log -Get-Job | Foreach-object { +Get-Job | ForEach-Object { $msg = "Job: {0} {1} [{2}]" -f $_.name, $_.state, ( New-TimeSpan -Start $_.PSBeginTime -End $_.PSEndTime) log $msg } @@ -102,6 +102,6 @@ Get-Date | Out-File -FilePath c:\scripts\sandbox.flag log "Sending toast notification in the Windows Sandbox" &(Join-Path -Path $SetupPath -ChildPath sandbox-toast.ps1) -log "Ending configuration script $($myinvocation.MyCommand)" +log "Ending configuration script $($MyInvocation.MyCommand)" log "Configuration completed in $(New-Timespan -start $begin)" log "Have a nice day!"