From 2f08d087f0c6fe291253134d3f18e1d5f3317388 Mon Sep 17 00:00:00 2001 From: DarkChaos Date: Tue, 21 Jul 2020 20:57:30 +0200 Subject: [PATCH 1/5] Replaced Write-Host with Write-Output http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/ --- .../DeployWindowsService.ps1 | 39 ++++++++++--------- .../WindowsServiceManagerPS.ps1 | 30 +++++++------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 index 2e2e0d7..f7b2519 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 @@ -85,7 +85,7 @@ $UTILITY_PATH = Join-Path -Path $PSScriptRoot -ChildPath 'ps_modules\WindowsServ if ($DeploymentType -eq 'Agent') { - Write-Host ("Begining deployment to [{0}]" -f ($Machines -join ', ')) + Write-Output ("Begining deployment to [{0}]" -f ($Machines -join ', ')) if (($null -ne $Password) -and ($null -ne $AdminLogin)) { @@ -139,24 +139,25 @@ $scriptBlock = { # Handle TopShelf service instance name if ($InstanceName.Length -ne 0) { - Write-Host "[$env:ComputerName]: Instance Name: [$InstanceName]" + Write-Output "[$env:ComputerName]: Instance Name: [$InstanceName]" $serviceName = "{0}`${1}" -f $ServiceName.split('$')[0], $InstanceName } - Write-Host "[$env:ComputerName]: Attempting to locate [$ServiceName]" + Write-Output "[$env:ComputerName]: Attempting to locate [$ServiceName]" $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName if ($serviceObject) { if($RecreateService) { - Write-Host "[$env:ComputerName]: Recreate service set to [$RecreateService]" - Write-Host "[$env:ComputerName]: Stopping the service [$ServiceName]" + Write-Output "[$env:ComputerName]: Recreate service set to [$RecreateService]" + Write-Output "[$env:ComputerName]: Stopping the service [$ServiceName]" $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName - Write-Host "[$env:ComputerName]: Deleting the service [$ServiceName]" - $deleteResults = $serviceObject.Delete() + Write-Output "[$env:ComputerName]: Deleting the service [$ServiceName]" + + $deleteResults = $serviceObject.Delete() if($deleteResults.ReturnValue -eq 0) { - Write-Host "[$env:ComputerName]: Successfully removed [$ServiceName]" + Write-Output "[$env:ComputerName]: Successfully removed [$ServiceName]" } else { @@ -166,7 +167,7 @@ $scriptBlock = { } else { - Write-Host "[$env:ComputerName]: Unable to locate [$ServiceName]." + Write-Output "[$env:ComputerName]: Unable to locate [$ServiceName]." } # Install service @@ -174,7 +175,7 @@ $scriptBlock = { { $parentPath = Get-WSMFullExecuteablePath -StringContainingPath $InstallationPath -JustParentPath New-WSMServiceDirectory -ParentPath $parentPath - Write-Host "[$env:ComputerName]: Creating service [$ServiceName]." + Write-Output "[$env:ComputerName]: Creating service [$ServiceName]." if ($InstallTopShelfService) { # Binaires needed to complete install for TopShelf @@ -197,7 +198,7 @@ $scriptBlock = { $arguments += $InstallArguments } - Write-Host "[$env:ComputerName]: Installing topshelf with arguments $arguments" + Write-Output "[$env:ComputerName]: Installing topshelf with arguments $arguments" & $installationPath $arguments $freshTopShelfInstall = $true } @@ -222,17 +223,17 @@ $scriptBlock = { } if ($runAsCredential) { - Write-Host "[$env:ComputerName]: Setting RunAsCredentials" + Write-Output "[$env:ComputerName]: Setting RunAsCredentials" $newServiceSplat.Credential = $runAsCredential - Write-Host "[$env:ComputerName]: Granting [$($runAsCredential.UserName)] logon as a service rights" + Write-Output "[$env:ComputerName]: Granting [$($runAsCredential.UserName)] logon as a service rights" Add-LocalUserToLogonAsAService -user $runAsCredential.UserName } $null = New-Service @newServiceSplat - Write-Host "[$env:ComputerName]: Service [$ServiceName] created." + Write-Output "[$env:ComputerName]: Service [$ServiceName] created." if ($delayed) { - Write-Host "[$env:ComputerName]: Set [$ServiceName] to delayed start" + Write-Output "[$env:ComputerName]: Set [$ServiceName] to delayed start" Start-Process -FilePath sc.exe -ArgumentList "config ""$ServiceName"" start=delayed-auto" } } @@ -251,14 +252,14 @@ $scriptBlock = { { $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName -Timeout $Timeout -StopProcess:$StopProcess $parentPath = Get-WSMFullExecuteablePath -StringContainingPath $serviceObject.PathName -JustParentPath - Write-Host "[$env:ComputerName]: Identified [$ServiceName] installation directory [$parentPath]" + Write-Output "[$env:ComputerName]: Identified [$ServiceName] installation directory [$parentPath]" if (Test-Path $parentPath) { if ($CleanInstall) { - Write-Host "[$env:ComputerName]: Clean install set to [$CleanInstall], removing the contents of [$parentPath]" + Write-Output "[$env:ComputerName]: Clean install set to [$CleanInstall], removing the contents of [$parentPath]" Invoke-WSMCleanInstall -ParentPath $parentPath -StopProcess $StopProcess -Timeout $TimeOut -ServiceName $ServiceName } } @@ -315,8 +316,8 @@ $invokeCommandSplat = @{ $InstallService } -# Import utility script into session -Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH + # Import utility script into session + Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH # Invoke script block Invoke-Command @invokeCommandSplat -ScriptBlock $scriptBlock diff --git a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 index 0797af1..a45a185 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 @@ -25,18 +25,18 @@ function Add-LocalUserToLogonAsAService $sidstr = $null } - Write-Host "Account: $($user)" -ForegroundColor DarkCyan + Write-Output "Account: $($user)" -ForegroundColor DarkCyan if ( [string]::IsNullOrEmpty($sidstr) ) { return Write-Error "Account not found!" } - Write-Host "Account SID: $($sidstr)" -ForegroundColor DarkCyan + Write-Output "Account SID: $($sidstr)" -ForegroundColor DarkCyan $tmp = [System.IO.Path]::GetTempFileName() - Write-Host "Export current Local Security Policy" -ForegroundColor DarkCyan + Write-Output "Export current Local Security Policy" -ForegroundColor DarkCyan secedit.exe /export /cfg "$($tmp)" $c = Get-Content -Path $tmp @@ -54,7 +54,7 @@ function Add-LocalUserToLogonAsAService if ( $currentSetting -notlike "*$($sidstr)*" ) { - Write-Host "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan + Write-Output "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan if ( [string]::IsNullOrEmpty($currentSetting) ) { @@ -65,7 +65,7 @@ function Add-LocalUserToLogonAsAService $currentSetting = "*$($sidstr),$($currentSetting)" } - Write-Host "$currentSetting" + Write-Output "$currentSetting" $outfile = @" [Unicode] @@ -80,7 +80,7 @@ SeServiceLogonRight = $($currentSetting) $tmp2 = [System.IO.Path]::GetTempFileName() - Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan + Write-Output "Import new settings to Local Security Policy" -ForegroundColor DarkCyan $outfile | Set-Content -Path $tmp2 -Encoding Unicode -Force #notepad.exe $tmp2 @@ -89,7 +89,7 @@ SeServiceLogonRight = $($currentSetting) try { secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS - #write-host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " + #Write-Output "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " } finally { @@ -98,10 +98,10 @@ SeServiceLogonRight = $($currentSetting) } else { - Write-Host "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan + Write-Output "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan } - Write-Host "Done." -ForegroundColor DarkCyan + Write-Output "Done." -ForegroundColor DarkCyan } } @@ -140,7 +140,7 @@ function Start-WSMWindowsService ( $ServiceName ) - Write-Host "[$env:ComputerName]: Starting [$ServiceName]" + Write-Output "[$env:ComputerName]: Starting [$ServiceName]" $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName $respone = $serviceObject.StartService() if ($respone.ReturnValue -ne 0) @@ -149,7 +149,7 @@ function Start-WSMWindowsService } else { - Write-Host "[$env:ComputerName]: [$ServiceName] started successfully!" + Write-Output "[$env:ComputerName]: [$ServiceName] started successfully!" } } @@ -173,7 +173,7 @@ function Stop-WSMWindowsService if ($serviceObject.State -eq 'Running') { $stopServiceTimer = [Diagnostics.Stopwatch]::StartNew() - Write-Host "[$env:ComputerName]: Stopping Service [$ServiceName]" + Write-Output "[$env:ComputerName]: Stopping Service [$ServiceName]" do { $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName @@ -204,7 +204,7 @@ function Stop-WSMWindowsService } while ($serviceObject.State -ne 'Stopped') - Write-Host "[$env:ComputerName]: Stopped Service [$ServiceName]" + Write-Output "[$env:ComputerName]: Stopped Service [$ServiceName]" } return $serviceObject } @@ -250,7 +250,7 @@ function New-WSMServiceDirectory ) if (-not(Test-Path $ParentPath)) { - Write-Host "[$env:ComputerName]: Creating the service directory at [$ParentPath]." + Write-Output "[$env:ComputerName]: Creating the service directory at [$ParentPath]." $null = New-Item -Path $ParentPath -ItemType 'Directory' -Force } } @@ -265,7 +265,7 @@ function Copy-WSMServiceBinaries [string] $ParentPath ) - Write-Host "[$env:ComputerName]: Copying [$ArtifactPath] to [$ParentPath]" + Write-Output "[$env:ComputerName]: Copying [$ArtifactPath] to [$ParentPath]" if ($ArtifactPath.EndsWith('.zip')) { Expand-Archive -Path $ArtifactPath -DestinationPath $ParentPath -Force -ErrorAction Stop From 53f22436251ebff57e16fa8751b21ba8f5981fb9 Mon Sep 17 00:00:00 2001 From: DarkChaos Date: Wed, 22 Jul 2020 11:08:18 +0200 Subject: [PATCH 2/5] Fixed #42 --- .../WindowsServiceManagerV5/DeployWindowsService.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 index f7b2519..2eb9ae8 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 @@ -154,10 +154,19 @@ $scriptBlock = { $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName Write-Output "[$env:ComputerName]: Deleting the service [$ServiceName]" + try { $deleteResults = $serviceObject.Delete() + } + catch { + Write-Error "[$env:ComputerName]: Failing remove Service [$ServiceName]. Used ServiceObject [$serviceObject]" + Write-Error $_.Exception.Message + return + } + if($deleteResults.ReturnValue -eq 0) { Write-Output "[$env:ComputerName]: Successfully removed [$ServiceName]" + $serviceObject = $null } else { From fefea780413f94049862c1d7fd35b7526c23fd18 Mon Sep 17 00:00:00 2001 From: DarkChaos Date: Wed, 22 Jul 2020 11:09:51 +0200 Subject: [PATCH 3/5] changed sequence of invokecommand to fix DeploymentGroup issue --- .../DeployWindowsService.ps1 | 30 +++++++++---------- .../WindowsServiceManagerV5/task.json | 2 +- vss-extension.json | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 index 2eb9ae8..951391b 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 @@ -290,22 +290,7 @@ $scriptBlock = { } -if ($Machines) -{ - $newPSSessionSPlat = @{ - ComputerName = $Machines - SessionOption = $sessionOption - UseSSL = $UseSSL - } - if ($credential) - { - $newPSSessionSPlat.Credential = $credential - } - $sessions = New-PSSession @newPSSessionSPlat -} - $invokeCommandSplat = @{ - Session = $sessions ArgumentList = $ServiceName, $ServiceDisplayName, $ServiceDescription, @@ -325,8 +310,23 @@ $invokeCommandSplat = @{ $InstallService } +if ($Machines) +{ + $newPSSessionSPlat = @{ + ComputerName = $Machines + SessionOption = $sessionOption + UseSSL = $UseSSL + } + if ($credential) + { + $newPSSessionSPlat.Credential = $credential + } + $sessions = New-PSSession @newPSSessionSPlat + $invokeCommandSplat.Session = $sessions + # Import utility script into session Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH +} # Invoke script block Invoke-Command @invokeCommandSplat -ScriptBlock $scriptBlock diff --git a/WindowsServiceManager/WindowsServiceManagerV5/task.json b/WindowsServiceManager/WindowsServiceManagerV5/task.json index 5dd3de7..a86d894 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/task.json +++ b/WindowsServiceManager/WindowsServiceManagerV5/task.json @@ -14,7 +14,7 @@ "version": { "Major": 5, "Minor": 0, - "Patch": 1 + "Patch": 4 }, "instanceNameFormat": "Deploy Windows Service", "groups": [ diff --git a/vss-extension.json b/vss-extension.json index 154c4a7..8e0a5a3 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "WindowsServiceManager", - "version": "5.0.3", + "version": "5.0.6", "name": "Windows Service Manager", "description": "Installs and deploys a windows service or TopShelf service on a target machine or a deployment group target.", "publisher": "MDSolutions", From e1e7e866231c6f1397e696e361c867828e28f868 Mon Sep 17 00:00:00 2001 From: DarkChaos Date: Tue, 28 Jul 2020 15:14:32 +0200 Subject: [PATCH 4/5] clearifyed Error Message, returned to Write-Host --- .../DeployWindowsService.ps1 | 32 +++++++++---------- .../WindowsServiceManagerPS.ps1 | 32 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 index 951391b..10ed755 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 @@ -85,7 +85,7 @@ $UTILITY_PATH = Join-Path -Path $PSScriptRoot -ChildPath 'ps_modules\WindowsServ if ($DeploymentType -eq 'Agent') { - Write-Output ("Begining deployment to [{0}]" -f ($Machines -join ', ')) + Write-Host ("Begining deployment to [{0}]" -f ($Machines -join ', ')) if (($null -ne $Password) -and ($null -ne $AdminLogin)) { @@ -139,20 +139,20 @@ $scriptBlock = { # Handle TopShelf service instance name if ($InstanceName.Length -ne 0) { - Write-Output "[$env:ComputerName]: Instance Name: [$InstanceName]" + Write-Host "[$env:ComputerName]: Instance Name: [$InstanceName]" $serviceName = "{0}`${1}" -f $ServiceName.split('$')[0], $InstanceName } - Write-Output "[$env:ComputerName]: Attempting to locate [$ServiceName]" + Write-Host "[$env:ComputerName]: Attempting to locate [$ServiceName]" $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName if ($serviceObject) { if($RecreateService) { - Write-Output "[$env:ComputerName]: Recreate service set to [$RecreateService]" - Write-Output "[$env:ComputerName]: Stopping the service [$ServiceName]" + Write-Host "[$env:ComputerName]: Recreate service set to [$RecreateService]" + Write-Host "[$env:ComputerName]: Stopping the service [$ServiceName]" $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName - Write-Output "[$env:ComputerName]: Deleting the service [$ServiceName]" + Write-Host "[$env:ComputerName]: Deleting the service [$ServiceName]" try { $deleteResults = $serviceObject.Delete() @@ -165,7 +165,7 @@ $scriptBlock = { if($deleteResults.ReturnValue -eq 0) { - Write-Output "[$env:ComputerName]: Successfully removed [$ServiceName]" + Write-Host "[$env:ComputerName]: Successfully removed [$ServiceName]" $serviceObject = $null } else @@ -176,7 +176,7 @@ $scriptBlock = { } else { - Write-Output "[$env:ComputerName]: Unable to locate [$ServiceName]." + Write-Host "[$env:ComputerName]: Unable to locate [$ServiceName]." } # Install service @@ -184,7 +184,7 @@ $scriptBlock = { { $parentPath = Get-WSMFullExecuteablePath -StringContainingPath $InstallationPath -JustParentPath New-WSMServiceDirectory -ParentPath $parentPath - Write-Output "[$env:ComputerName]: Creating service [$ServiceName]." + Write-Host "[$env:ComputerName]: Creating service [$ServiceName]." if ($InstallTopShelfService) { # Binaires needed to complete install for TopShelf @@ -207,7 +207,7 @@ $scriptBlock = { $arguments += $InstallArguments } - Write-Output "[$env:ComputerName]: Installing topshelf with arguments $arguments" + Write-Host "[$env:ComputerName]: Installing topshelf with arguments $arguments" & $installationPath $arguments $freshTopShelfInstall = $true } @@ -232,17 +232,17 @@ $scriptBlock = { } if ($runAsCredential) { - Write-Output "[$env:ComputerName]: Setting RunAsCredentials" + Write-Host "[$env:ComputerName]: Setting RunAsCredentials" $newServiceSplat.Credential = $runAsCredential - Write-Output "[$env:ComputerName]: Granting [$($runAsCredential.UserName)] logon as a service rights" + Write-Host "[$env:ComputerName]: Granting [$($runAsCredential.UserName)] logon as a service rights" Add-LocalUserToLogonAsAService -user $runAsCredential.UserName } $null = New-Service @newServiceSplat - Write-Output "[$env:ComputerName]: Service [$ServiceName] created." + Write-Host "[$env:ComputerName]: Service [$ServiceName] created." if ($delayed) { - Write-Output "[$env:ComputerName]: Set [$ServiceName] to delayed start" + Write-Host "[$env:ComputerName]: Set [$ServiceName] to delayed start" Start-Process -FilePath sc.exe -ArgumentList "config ""$ServiceName"" start=delayed-auto" } } @@ -261,14 +261,14 @@ $scriptBlock = { { $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName -Timeout $Timeout -StopProcess:$StopProcess $parentPath = Get-WSMFullExecuteablePath -StringContainingPath $serviceObject.PathName -JustParentPath - Write-Output "[$env:ComputerName]: Identified [$ServiceName] installation directory [$parentPath]" + Write-Host "[$env:ComputerName]: Identified [$ServiceName] installation directory [$parentPath]" if (Test-Path $parentPath) { if ($CleanInstall) { - Write-Output "[$env:ComputerName]: Clean install set to [$CleanInstall], removing the contents of [$parentPath]" + Write-Host "[$env:ComputerName]: Clean install set to [$CleanInstall], removing the contents of [$parentPath]" Invoke-WSMCleanInstall -ParentPath $parentPath -StopProcess $StopProcess -Timeout $TimeOut -ServiceName $ServiceName } } diff --git a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 index a45a185..4b38a53 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 @@ -25,18 +25,18 @@ function Add-LocalUserToLogonAsAService $sidstr = $null } - Write-Output "Account: $($user)" -ForegroundColor DarkCyan + Write-Host "Account: $($user)" -ForegroundColor DarkCyan if ( [string]::IsNullOrEmpty($sidstr) ) { return Write-Error "Account not found!" } - Write-Output "Account SID: $($sidstr)" -ForegroundColor DarkCyan + Write-Host "Account SID: $($sidstr)" -ForegroundColor DarkCyan $tmp = [System.IO.Path]::GetTempFileName() - Write-Output "Export current Local Security Policy" -ForegroundColor DarkCyan + Write-Host "Export current Local Security Policy" -ForegroundColor DarkCyan secedit.exe /export /cfg "$($tmp)" $c = Get-Content -Path $tmp @@ -54,7 +54,7 @@ function Add-LocalUserToLogonAsAService if ( $currentSetting -notlike "*$($sidstr)*" ) { - Write-Output "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan + Write-Host "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan if ( [string]::IsNullOrEmpty($currentSetting) ) { @@ -65,7 +65,7 @@ function Add-LocalUserToLogonAsAService $currentSetting = "*$($sidstr),$($currentSetting)" } - Write-Output "$currentSetting" + Write-Host "$currentSetting" $outfile = @" [Unicode] @@ -80,7 +80,7 @@ SeServiceLogonRight = $($currentSetting) $tmp2 = [System.IO.Path]::GetTempFileName() - Write-Output "Import new settings to Local Security Policy" -ForegroundColor DarkCyan + Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan $outfile | Set-Content -Path $tmp2 -Encoding Unicode -Force #notepad.exe $tmp2 @@ -89,7 +89,7 @@ SeServiceLogonRight = $($currentSetting) try { secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS - #Write-Output "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " + #Write-Host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " } finally { @@ -98,10 +98,10 @@ SeServiceLogonRight = $($currentSetting) } else { - Write-Output "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan + Write-Host "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan } - Write-Output "Done." -ForegroundColor DarkCyan + Write-Host "Done." -ForegroundColor DarkCyan } } @@ -140,7 +140,7 @@ function Start-WSMWindowsService ( $ServiceName ) - Write-Output "[$env:ComputerName]: Starting [$ServiceName]" + Write-Host "[$env:ComputerName]: Starting [$ServiceName]" $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName $respone = $serviceObject.StartService() if ($respone.ReturnValue -ne 0) @@ -149,7 +149,7 @@ function Start-WSMWindowsService } else { - Write-Output "[$env:ComputerName]: [$ServiceName] started successfully!" + Write-Host "[$env:ComputerName]: [$ServiceName] started successfully!" } } @@ -173,7 +173,7 @@ function Stop-WSMWindowsService if ($serviceObject.State -eq 'Running') { $stopServiceTimer = [Diagnostics.Stopwatch]::StartNew() - Write-Output "[$env:ComputerName]: Stopping Service [$ServiceName]" + Write-Host "[$env:ComputerName]: Stopping Service [$ServiceName]" do { $serviceObject = Get-WSMWindowsService -ServiceName $ServiceName @@ -204,7 +204,7 @@ function Stop-WSMWindowsService } while ($serviceObject.State -ne 'Stopped') - Write-Output "[$env:ComputerName]: Stopped Service [$ServiceName]" + Write-Host "[$env:ComputerName]: Stopped Service [$ServiceName]" } return $serviceObject } @@ -226,7 +226,7 @@ function Get-WSMFullExecuteablePath # check if PathName can be processed if ($StringContainingPath -notmatch $matchPattern) { - return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path ending with an '.exe' or '.dll'. Current string [$StringContainingPath]" + return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path without spaces or wrapped in quotes and ending with an '.exe' or '.dll'. Current string [$StringContainingPath]" } # extract Path @@ -250,7 +250,7 @@ function New-WSMServiceDirectory ) if (-not(Test-Path $ParentPath)) { - Write-Output "[$env:ComputerName]: Creating the service directory at [$ParentPath]." + Write-Host "[$env:ComputerName]: Creating the service directory at [$ParentPath]." $null = New-Item -Path $ParentPath -ItemType 'Directory' -Force } } @@ -265,7 +265,7 @@ function Copy-WSMServiceBinaries [string] $ParentPath ) - Write-Output "[$env:ComputerName]: Copying [$ArtifactPath] to [$ParentPath]" + Write-Host "[$env:ComputerName]: Copying [$ArtifactPath] to [$ParentPath]" if ($ArtifactPath.EndsWith('.zip')) { Expand-Archive -Path $ArtifactPath -DestinationPath $ParentPath -Force -ErrorAction Stop From a0dd238949f8171a56bd5c3ce91adc8bd98e2bd7 Mon Sep 17 00:00:00 2001 From: DarkChaos Date: Tue, 28 Jul 2020 15:18:05 +0200 Subject: [PATCH 5/5] fixed / worked around a String issue in powershell --- .../WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 | 5 ++++- WindowsServiceManager/WindowsServiceManagerV5/task.json | 2 +- vss-extension.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 index 4b38a53..fc3d5d9 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 @@ -220,11 +220,14 @@ function Get-WSMFullExecuteablePath [switch] $JustParentPath = $false ) + Write-Verbose "StartCommand=[$StartCommand]" + Write-Verbose "StringContainingPath=[$StringContainingPath]" # pattern to analyse Service Startup Command $matchPattern = '( |^)(?([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄÜ°^!§$%&=`´,;@#+._-]+)(.exe|.dll))|(( "|^")(?(([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄÜ°^!§$%&=`´,;@#+._ -]+)(.exe|.dll)))(" |"$))' # check if PathName can be processed - if ($StringContainingPath -notmatch $matchPattern) + #if ($StringContainingPath -notmatch $matchPattern) + if ($StartCommand -notmatch $matchPattern) #as workaround it will not be Used the parameter. The function Parameter always trims the Quotes. { return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path without spaces or wrapped in quotes and ending with an '.exe' or '.dll'. Current string [$StringContainingPath]" } diff --git a/WindowsServiceManager/WindowsServiceManagerV5/task.json b/WindowsServiceManager/WindowsServiceManagerV5/task.json index a86d894..80aa3b8 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/task.json +++ b/WindowsServiceManager/WindowsServiceManagerV5/task.json @@ -14,7 +14,7 @@ "version": { "Major": 5, "Minor": 0, - "Patch": 4 + "Patch": 5 }, "instanceNameFormat": "Deploy Windows Service", "groups": [ diff --git a/vss-extension.json b/vss-extension.json index 8e0a5a3..c0e4bb6 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "WindowsServiceManager", - "version": "5.0.6", + "version": "5.0.7", "name": "Windows Service Manager", "description": "Installs and deploys a windows service or TopShelf service on a target machine or a deployment group target.", "publisher": "MDSolutions",