@@ -36,24 +36,47 @@ Param(
36
36
# $ScreenCaptureProtection
37
37
)
38
38
39
- # #############################################################
40
- # Functions
41
- # #############################################################
42
- function Write-Log {
43
- param (
44
- [parameter (Mandatory )]
45
- [string ]$Message ,
39
+ function New-Log {
40
+ Param (
41
+ [Parameter (Mandatory = $true , Position = 0 )]
42
+ [string ] $Path
43
+ )
44
+
45
+ $date = Get-Date - UFormat " %Y-%m-%d %H-%M-%S"
46
+ Set-Variable logFile - Scope Script
47
+ $script :logFile = " $Script :Name -$date .log"
48
+
49
+ if ((Test-Path $path ) -eq $false ) {
50
+ $null = New-Item - Path $path - type directory
51
+ }
52
+
53
+ $script :Log = Join-Path $path $logfile
54
+
55
+ Add-Content $script :Log " Date`t`t`t Category`t`t Details"
56
+ }
46
57
47
- [parameter (Mandatory )]
48
- [string ]$Type
58
+ function Write-Log {
59
+ Param (
60
+ [Parameter (Mandatory = $false , Position = 0 )]
61
+ [ValidateSet (" Info" , " Warning" , " Error" )]
62
+ $Category = ' Info' ,
63
+ [Parameter (Mandatory = $true , Position = 1 )]
64
+ $Message
49
65
)
50
- $Path = ' C:\Windows\Temp\AVDSessionHostConfig.log'
51
- if (! (Test-Path - Path $Path )) {
52
- New-Item - Path ' C:\' - Name ' AVDSessionHostConfig.log' | Out-Null
66
+
67
+ $Date = get-date
68
+ $Content = " [$Date ]`t $Category `t`t $Message `n "
69
+ Add-Content $Script :Log $content - ErrorAction Stop
70
+ If ($Verbose ) {
71
+ Write-Verbose $Content
72
+ }
73
+ Else {
74
+ Switch ($Category ) {
75
+ ' Info' { Write-Host $content }
76
+ ' Error' { Write-Error $Content }
77
+ ' Warning' { Write-Warning $Content }
78
+ }
53
79
}
54
- $Timestamp = Get-Date - Format ' MM/dd/yyyy HH:mm:ss.ff'
55
- $Entry = ' [' + $Timestamp + ' ] [' + $Type + ' ] ' + $Message
56
- $Entry | Out-File - FilePath $Path - Append
57
80
}
58
81
59
82
function Get-WebFile {
@@ -78,51 +101,53 @@ function Get-WebFile {
78
101
Function Set-RegistryValue {
79
102
[CmdletBinding ()]
80
103
param (
81
- [Parameter ()]
82
- [string ]
83
- $Name ,
84
- [Parameter ()]
85
- [string ]
86
- $Path ,
87
- [Parameter ()]
88
- [string ]$PropertyType ,
89
- [Parameter ()]
90
- $Value
104
+ [Parameter ()]
105
+ [string ]
106
+ $Name ,
107
+ [Parameter ()]
108
+ [string ]
109
+ $Path ,
110
+ [Parameter ()]
111
+ [string ]$PropertyType ,
112
+ [Parameter ()]
113
+ $Value
91
114
)
92
115
Begin {
93
- Write-Log - message " [Set-RegistryValue]: Setting Registry Value: $Name "
116
+ Write-Log - message " [Set-RegistryValue]: Setting Registry Value: $Name "
94
117
}
95
118
Process {
96
- # Create the registry Key(s) if necessary.
97
- If (! (Test-Path - Path $Path )) {
98
- Write-Log - message " [Set-RegistryValue]: Creating Registry Key: $Path "
99
- New-Item - Path $Path - Force | Out-Null
100
- }
101
- # Check for existing registry setting
102
- $RemoteValue = Get-ItemProperty - Path $Path - Name $Name - ErrorAction SilentlyContinue
103
- If ($RemoteValue ) {
104
- # Get current Value
105
- $CurrentValue = Get-ItemPropertyValue - Path $Path - Name $Name
106
- Write-Log - message " [Set-RegistryValue]: Current Value of $ ( $Path ) \$ ( $Name ) : $CurrentValue "
107
- If ($Value -ne $CurrentValue ) {
108
- Write-Log - message " [Set-RegistryValue]: Setting Value of $ ( $Path ) \$ ( $Name ) : $Value "
109
- Set-ItemProperty - Path $Path - Name $Name - Value $Value - Force | Out-Null
110
- } Else {
111
- Write-Log - message " [Set-RegistryValue]: Value of $ ( $Path ) \$ ( $Name ) is already set to $Value "
112
- }
113
- }
114
- Else {
115
- Write-Log - message " [Set-RegistryValue]: Setting Value of $ ( $Path ) \$ ( $Name ) : $Value "
116
- New-ItemProperty - Path $Path - Name $Name - PropertyType $PropertyType - Value $Value - Force | Out-Null
117
- }
118
- Start-Sleep - Milliseconds 500
119
+ # Create the registry Key(s) if necessary.
120
+ If (! (Test-Path - Path $Path )) {
121
+ Write-Log - message " [Set-RegistryValue]: Creating Registry Key: $Path "
122
+ New-Item - Path $Path - Force | Out-Null
123
+ }
124
+ # Check for existing registry setting
125
+ $RemoteValue = Get-ItemProperty - Path $Path - Name $Name - ErrorAction SilentlyContinue
126
+ If ($RemoteValue ) {
127
+ # Get current Value
128
+ $CurrentValue = Get-ItemPropertyValue - Path $Path - Name $Name
129
+ Write-Log - message " [Set-RegistryValue]: Current Value of $ ( $Path ) \$ ( $Name ) : $CurrentValue "
130
+ If ($Value -ne $CurrentValue ) {
131
+ Write-Log - message " [Set-RegistryValue]: Setting Value of $ ( $Path ) \$ ( $Name ) : $Value "
132
+ Set-ItemProperty - Path $Path - Name $Name - Value $Value - Force | Out-Null
133
+ }
134
+ Else {
135
+ Write-Log - message " [Set-RegistryValue]: Value of $ ( $Path ) \$ ( $Name ) is already set to $Value "
136
+ }
137
+ }
138
+ Else {
139
+ Write-Log - message " [Set-RegistryValue]: Setting Value of $ ( $Path ) \$ ( $Name ) : $Value "
140
+ New-ItemProperty - Path $Path - Name $Name - PropertyType $PropertyType - Value $Value - Force | Out-Null
141
+ }
142
+ Start-Sleep - Milliseconds 500
119
143
}
120
144
End {
121
145
}
122
- }
146
+ }
123
147
124
148
$ErrorActionPreference = ' Stop'
125
-
149
+ $Script :Name = ' Set-SessionHostConfiguration'
150
+ New-Log - Path (Join-Path - Path $env: SystemRoot - ChildPath ' Logs' )
126
151
try {
127
152
128
153
# #############################################################
@@ -333,7 +358,8 @@ try {
333
358
$CMDKey = Start-Process - FilePath ' cmdkey.exe' - ArgumentList " /add:$FSLogixStorageFQDN /user:localhost\$SAName /pass:$FSLogixStorageAccountKey " - Wait - PassThru
334
359
If ($CMDKey.ExitCode -ne 0 ) {
335
360
Write-Log - Message " CMDKey Failed with '$ ( $CMDKey.ExitCode ) '. Failed to add Local Storage Account Key for '$FSLogixStorageFQDN ' to Credential Manager" - Type ' ERROR'
336
- } Else {
361
+ }
362
+ Else {
337
363
Write-Log - Message " Successfully added Local Storage Account Key for '$FSLogixStorageFQDN ' to Credential Manager" - Type ' INFO'
338
364
}
339
365
$Settings += @ (
@@ -384,7 +410,7 @@ try {
384
410
385
411
# Resize OS Disk
386
412
Write-Log - message " Resizing OS Disk"
387
- $driveLetter = $env: SystemDrive.Substring (0 , 1 )
413
+ $driveLetter = $env: SystemDrive.Substring (0 , 1 )
388
414
$size = Get-PartitionSupportedSize - DriveLetter $driveLetter
389
415
Resize-Partition - DriveLetter $driveLetter - Size $size.SizeMax
390
416
Write-Log - message " OS Disk Resized"
0 commit comments