/build/static/layout/Breadcrumb_cap_w.png

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
  • You'd have to post your scripts and let us know where it's hanging. Alternatively if it only happens with PowerShell v4, could you specify the version parameter when you call powershell.exe (example: powershell.exe -version 3 .\example.ps1) when you call it from the BAT file so that you run the PowerShell script with a specific version of PowerShell? - captain_planet 5 years ago
    • Sorry, my brain has melted today, I've added them in. The -version didn't seem to work but I may be using it wrong. - dsalt 5 years ago
  • You could try: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Version 2 -ExecutionPolicy ByPass -WindowStyle Hidden -File "\\server\packages\Information@Work_5.1_Corp\Install.ps1"

    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 5 years ago
    • I think this might have done the trick. It's erroring after being launched but I think that's down to it ignoring the .iss file that does the configuration so just need to get around that now. - dsalt 5 years ago
      • Ok goo. I'll add it as an answer in that case. - captain_planet 5 years ago
  • There's usually also an installation log file for those setup.exe's so check that too.... - captain_planet 5 years ago

Answers (1)

Answer Summary:
Posted by: captain_planet 5 years ago
Black Belt
1

Top Answer

Try:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Version 2 -ExecutionPolicy ByPass -WindowStyle Hidden -File "\\server\packages\Information@Work_5.1_Corp\Install.ps1"

Doing it this way just sets the execution policy for the session.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ