Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Jun 21, 2023
1 parent 4698684 commit 9f2a0b7
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 169 deletions.
Binary file modified License.txt
Binary file not shown.
Binary file modified WindowsSandboxTools.psd1
Binary file not shown.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/Export-WsbConfiguration.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
6 changes: 3 additions & 3 deletions docs/Get-WsbConfiguration.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
external help file: WindowsSandboxTools-help.xml
Module Name: WindowsSandboxTools
online version:
online version: https://bit.ly/44aWC9X
schema: 2.0.0
---

# Get-WsbConfiguration

## SYNOPSIS

Get a Windows Sandbox configuratoin.
Get a Windows Sandbox configuration.

## SYNTAX

Expand Down Expand Up @@ -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
```
Expand Down
4 changes: 2 additions & 2 deletions docs/New-WsbConfiguration.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down Expand Up @@ -279,4 +279,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
[New-WsbMappedFolder](New-WsbMappedFolder.md)
[Export-WsbConfiguration](Export-WsbConfiguration.md)
[Export-WsbConfiguration](Export-WsbConfiguration.md)
2 changes: 1 addition & 1 deletion docs/New-WsbMappedFolder.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
2 changes: 1 addition & 1 deletion docs/Start-WindowsSandbox.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
26 changes: 23 additions & 3 deletions en-us/WindowsSandboxTools-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://bit.ly/3PkXMvl</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>New-WsbConfiguration</maml:linkText>
<maml:uri></maml:uri>
Expand All @@ -183,7 +187,7 @@
<command:verb>Get</command:verb>
<command:noun>WsbConfiguration</command:noun>
<maml:description>
<maml:para>Get a Windows Sandbox configuratoin.</maml:para>
<maml:para>Get a Windows Sandbox configuration.</maml:para>
</maml:description>
</command:details>
<maml:description>
Expand All @@ -192,7 +196,7 @@
<command:syntax>
<command:syntaxItem>
<maml:name>Get-WsbConfiguration</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none">
<maml:name>Path</maml:name>
<maml:description>
<maml:para>Specify the path to the .wsb file. The command will autocomplete to the $wsbConfigPath variable.</maml:para>
Expand Down Expand Up @@ -230,7 +234,7 @@
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none">
<maml:name>Path</maml:name>
<maml:description>
<maml:para>Specify the path to the .wsb file. The command will autocomplete to the $wsbConfigPath variable.</maml:para>
Expand Down Expand Up @@ -303,6 +307,10 @@ Jeff C:\scripts\wsbconfig\dev.wsb A test wsb file 12/10/2020 8:50:03 AM</dev:c
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://bit.ly/44aWC9X</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>New-WsbConfiguration</maml:linkText>
<maml:uri></maml:uri>
Expand Down Expand Up @@ -904,6 +912,10 @@ Jeff C:\scripts\wsbconfig\dev.wsb A test wsb file 12/10/2020 8:50:03 AM</dev:c
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://bit.ly/3qSqCJA</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>New-WsbMappedFolder</maml:linkText>
<maml:uri></maml:uri>
Expand Down Expand Up @@ -1040,6 +1052,10 @@ PS C:\&gt; New-WsbConfiguration -Name work -MappedFolder $map -Description "Work
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://bit.ly/3PkPqUH</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>New-WsbConfiguration</maml:linkText>
<maml:uri></maml:uri>
Expand Down Expand Up @@ -1261,6 +1277,10 @@ PS C:\&gt; New-WsbConfiguration -Name work -MappedFolder $map -Description "Work
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://bit.ly/42Wde4i</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>Get-WsbConfiguration</maml:linkText>
<maml:uri></maml:uri>
Expand Down
36 changes: 18 additions & 18 deletions functions/Export-WsbConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,46 +25,46 @@ 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)
}
[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 {
Expand All @@ -79,18 +79,18 @@ 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."
}
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
}
106 changes: 61 additions & 45 deletions functions/Get-WsbConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 9f2a0b7

Please sign in to comment.