Powershell 4 Issue when executed Through Kace
Hi One and All,
Got a bit of a puzzle. I have a script I'm trying to push out through KACE (a BAT file that then launches PS script). The PS script works fine when I run it directly on the machine rather than launching it through KACE, however stops part way through and just sits there if I go through KACE. The script is in the same location as are the dependent files in both instances. This seems to only be happening with devices that have Powershell V4 installed. Don't suppose anyone has come across this before?
Hopefully the script is readable, it's probably not the most elegant as I've just started to really dig into Powershell
It fails at # Install New Information@Work client (v5.1)
The bat file contains the following...
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Set-ExecutionPolicy Unrestricted
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 2 -Command "Start-Process Powershell -Verb RunAs" "\\server\packages\Information@Work_5.1_Corp\Install.ps1"
Powershell....
$setup = "\\prometheus\packages\Information@Work_5.1_Corp\Setup.exe"
$ucsetup = "\\Prometheus\Packages\Information@Work_5.1_Corp\uc\Universal Capture 64-Bit.msi"
$setupargs = "/s /f1\\prometheus\packages\Information@Work_5.1_Corp\Setup.iss"
set-executionpolicy unrestricted
New-Item -Path c:\windows\temp\information@work_upgrade.txt -Type File
# Remove .Net Framework 4.6.1
$Path461Exists = Test-Path $path461
If ($Path461Exists -eq $true) {Start-Process $net461 -ArgumentList $netargs -Wait}
# Remove .Net Framework 4.6.2
$Path462Exists = Test-Path $path462
If ($Path462Exists -eq $true) {Start-Process $net462 -ArgumentList $netargs -Wait}
# Remove .Net Framework 4.7
$Path47Exists = Test-Path $path47
If ($Path47Exists -eq $true) {Start-Process $net47 -ArgumentList $netargs -Wait}
#Remove .Net Framework 4.7.2
$Path472Exists = Test-Path $path472
If ($Path472Exists -eq $true) {Start-Process $net472 -ArgumentList $netargs -Wait}
Start-Sleep -Seconds 120
# Install .Net Framework 4.5.2
$RegPath452Exists = Test-Path $regpath452
If ($RegPath452Exists -eq $false) {Start-Process $setup452 -ArgumentList $setupargs452 -Wait}
Stop-Process -Name Images4 -Force -Recurse -erroraction 'silentlycontinue'
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value $Error
$Error.Clear()
# Remove old components (v4.9)
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value "Begining removal of old components"
$RegPath1Exists = Test-Path $regpath1
If ($RegPath1Exists -eq $true) {Remove-Item -Path $regpath1 -Recurse}
$RegPath2Exists = Test-Path $regpath2
If ($RegPath2Exists -eq $true) {Remove-Item -Path $regpath2 -Recurse}
$RegPath3Exists = Test-Path $regpath3
If ($RegPath2Exists -eq $true) {Remove-Item -Path $regpath3 -Recurse}
$RegPath3Exists = Test-Path $regpath4
If ($RegPath2Exists -eq $true) {Remove-Item -Path $regpath4 -Recurse}
$Folder1Exists = Test-Path $oldpath1
If ($Folder1Exists -eq $true) {Remove-Item -Path $oldpath1 -Recurse -Force}
$Folder2Exists = Test-Path $oldpath2
If ($Folder2Exists -eq $true) {Remove-Item -Path $oldpath2 -Recurse -Force}
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value "Old components removed"
Add-Content -Path C:\windows\temp\escrupgrade.txt -Value $Error
$Error.Clear()
#Install Updated SQL NCLI
Start-Process \\prometheus\packages\Information@Work_5.1_Corp\sqlncli.msi -ArgumentList "/qn IACCEPTSQLNCLILICENSETERMS=YES" -Wait
# Install New Information@Work client (v5.1)
Start-Process $setup -ArgumentList $setupargs -Wait
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value "v5.1 Installed"
Add-Content -Path C:\windows\temp\escrupgrade.txt -Value $Error
$Error.Clear()
#Install Universal Caputre
start-process $ucsetup -Wait /qn
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value "Universal Caputure installed"
Add-Content -Path C:\windows\temp\escrupgrade.txt -Value $Error
$Error.Clear()
# Install Patch
Copy-Item -path '\\prometheus\packages\Information@Work_5.1_Corp\13\images4.exe' -Destination 'C:\Program Files (x86)\Images@Work\images4.exe' -Force
Add-Content -Path C:\windows\temp\information@work_upgrade.txt -Value "Patch installed"
Add-Content -Path C:\windows\temp\escrupgrade.txt -Value $Error
$Error.Clear()
#Set Reg Key
Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\Software\Wow6432Node\IMASYS\IMAGES4\Database -Name DataServer -Value BATTY
Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\Software\Wow6432Node\IMASYS\IMAGES4\CalloutDatabase -Name DataServer -Value BATTY
# Install .Net Framework 4.7.2
Start-Process $setup472 -ArgumentList $setupargs472
set-executionpolicy restricted
3 Comments
[ + ] Show comments
Answers (1)
Answer Summary:
Please log in to answer
Posted by:
captain_planet
6 years ago
Doing it this way just sets the execution policy for the session. Also do you need the RunAs verb? Can you not elevate the BAT sufficiently via KACE? - captain_planet 6 years ago