-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-WVDConfigurationFiles.ps1
More file actions
97 lines (83 loc) · 3.6 KB
/
Copy pathNew-WVDConfigurationFiles.ps1
File metadata and controls
97 lines (83 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, HelpMessage = "Specify the name of the configuration folder to create")]
[ValidateNotNullOrEmpty()]
[ValidatePattern("^[a-zA-Z0-9_-]+$")]
[string]$FolderName
)
<#
.SYNOPSIS
Creates a new WVD configuration folder with template files.
.DESCRIPTION
This function creates a new folder in the Configurations directory and copies
all template configuration files to the new folder.
.PARAMETER FolderName
The name of the configuration folder to create. Must contain only letters,
numbers, underscores, and hyphens.
.EXAMPLE
New-WVDConfigurationFiles -FolderName <your config name>
Ex. New-WVDConfigurationFiles -FolderName "W11_24H2"
Ex. New-WVDConfigurationFiles -FolderName "WS25_24H2"
Creates a new folder called <your config name> with all template files.
.NOTES
Author: Tim Muessig
Version: 2.0
Requires: PowerShell 5.1 or higher
#>
Function New-WVDConfigurationFiles {
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern("^[a-zA-Z0-9_-]+$")]
[string]$FolderName
)
process {
try {
# Define paths
$ConfigurationsRoot = Join-Path -Path $PSScriptRoot -ChildPath "Configurations"
$TemplatesFolder = Join-Path -Path $ConfigurationsRoot -ChildPath "Templates"
$TargetFolder = Join-Path -Path $ConfigurationsRoot -ChildPath $FolderName
# Validate that Templates folder exists
if (-not (Test-Path -Path $TemplatesFolder -PathType Container)) {
throw "Templates folder not found at: $TemplatesFolder"
}
# Check if target folder already exists
if (Test-Path -Path $TargetFolder) {
Write-Warning "Configuration folder '$FolderName' already exists at: $TargetFolder"
return $false
}
# Create the target folder
if ($PSCmdlet.ShouldProcess($TargetFolder, "Create directory")) {
Write-Verbose "Creating directory: $TargetFolder"
$NewFolder = New-Item -Path $TargetFolder -ItemType Directory -Force
Write-Host "Created configuration folder: $($NewFolder.FullName)" -ForegroundColor Green
}
# Copy template files
$TemplateFiles = Get-ChildItem -Path $TemplatesFolder -File
if ($TemplateFiles.Count -eq 0) {
Write-Warning "No template files found in: $TemplatesFolder"
return $false
}
if ($PSCmdlet.ShouldProcess($TargetFolder, "Copy template files")) {
Write-Verbose "Copying $($TemplateFiles.Count) template files to: $TargetFolder"
Copy-Item -Path "$TemplatesFolder\*" -Destination $TargetFolder -Force
Write-Host "Successfully copied $($TemplateFiles.Count) template files" -ForegroundColor Green
}
return $true
} catch {
Write-Error "Failed to create configuration files: $($_.Exception.Message)"
return $false
}
}
}
# Main execution
if (-not $PSBoundParameters.ContainsKey('WhatIf') -and -not $PSBoundParameters.ContainsKey('Confirm')) {
$result = New-WVDConfigurationFiles -FolderName $FolderName
if ($result) {
Write-Host "Configuration folder '$FolderName' created successfully!" -ForegroundColor Green
} else {
Write-Host "Failed to create configuration folder '$FolderName'" -ForegroundColor Red
exit 1
}
}