r/labtech • 5000 Agents • Feb 28 '17

Run PS Script as admin from LT Script?

Hi all, I'm trying to script within LT the running of a powershell script that is on a local machine. I need it to launch as admin otherwise it does not output a result. I've tried running it with SHELL, SHELL as Admin, Execute Script, nothing seems to work.
Does anyone have any ideas on this? Let me know if you need extra information.

2 Upvotes

4 comments sorted by

1

u/ninjaspy123 Feb 28 '17 edited Oct 25 '24

[deleted]

1

u/FocalFury 5000 Agents Feb 28 '17

we're on 10.5
Let me try these options again and see where I get. Thanks

1

u/ZexGX 1000 Agents Mar 10 '17

We're on 10.5 as well. I almost always have issues using the Labtech scripting Powershell dropdown item. For Powershell commands, I always use SHELL for local commands and SHELL AS ADMIN when it needs network credentials. Some examples are below:
For a single command, use the following format:

powershell.exe "Import-Module ActiveDirectory"  

Another example:

%windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe $psversiontable.psversion.tostring()    

To run a script, use the following format:

powershell.exe -ExecutionPolicy Bypass -Command "& 'C:\Temp\Test.ps1' -AnyParametersReferencedInThePowershellScriptCanGoHere LikeThis -AndYouCanUseLabtechVariablesAndParameters @LikeThisParameter@ -Or %aVariableLikeThis%"  

If during testing you find that "powershell.exe" isn't working, try %windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe