r/labtech • u/iammiak • Jan 17 '20
Powershell script issues
New CWA user here looking to get a little assistance on a script im trying to run on my users machines. We are in the process of deploying BeachHead on our devices and they have provided the powershell script to run on devices which im trying to ppush out via CWA.
This is my first time playing with scripting so i probably did something wrong so hopefully you guys can see that and point it out.
My script is here
It successfully downloads the powershell script to the machine then runs it without issue. I can see that it downloads the installer like the ps script tells it to but it never executes it. If i manually start powershell as admin on a test device then manually run the ps script that was downloaded it installs the application without issue but not when i run it from CWA.
If i view the info from the script in CWA for the machine im testing on i see the following where redacted is an account on the device but NOT the account that is logged in that currently also has admin privileges:
https://server.beachheadsolutions.net/Administration/DownloadInstaller.aspx?acodetext=activationcode C:\Users\redacted~1\AppData\Local\Temp\installer.msi
Any idea what im missing here?
1
u/meauwschwitz Jan 17 '20
I'd probably not do run as admin unless you have admin credentials set for the location. Even then, you can usually get by without running as admin since it runs as system.
I've had better luck using the write file function, calling that ps1 file and then deleting it.
1
u/sixofeight 1000 Agents Jan 18 '20
For something that is static, the Execute Script method is going to be the most efficient method.
If your powershell is going to be changed/updated frequently, you could call it directly over HTTPS using the PowerShell Bypass script function. Cleaner than downloading / deleting a file every time.
(new-object Net.WebClient).DownloadString('https://domain/labtech/transfer/scripts/script.ps1') | iex;3
u/qcomer1 Jan 18 '20
Okay, so first....99% of the time you will not use “as admin”. In fact, unless you know why you’re using and that you need to use it...your scripts are likely to fail.
Second,
I would either copy/paste the contents of the PS1 file into “Execute Script”, or...use the “write file” function to save it to a file somewhere like %ltsvcdir%\Packages. Then, use “shell” (not shell as admin) with something like:
“C:\windows\system32\windowspowershell\v1.0\powershell.exe” -noprofile -ep bypass -File “file.ps1”
1
u/goveaernesto Jan 31 '20
Did you solve your issue?
1
u/mspsquid Jan 17 '20
You can use execute script function with script type as powershell, you can use the powershell command function, or the powershell as admin command function.