Wrap PsExec into PSADT


To start from my site, I’m definitely not a PS expert, I’m working a lot with SCCM and deployment, so I’m touching with PS everyday, but not doing the deep dive development :slight_smile:

We are deploying a application (i will just call it Google Chrome) for a customer and I have a PoweShell script that does it for me.

Not being too detailed, the script runs PsExec.exe with -U -P parameter, so I can install as a local admin service account that we have on all machines. The script looks like this:

[String]$InstallParameters="/Q /C C:\Temp\GoogleChrome.xml")

$user = "$env:computername\SVC_StoreUser"
$password = "P@ssw0rd"

Write-Debug "$($(get-location).Path)\$($InstallFile)"
$PSExec = """$($(get-location).Path)\psexec.exe"""
$Arguments = "-AcceptEula -i -h -u $($user) -p $($password) ""$($(get-location).Path)\$($InstallFile)"" $($InstallParameters)"
$ArguemntsWithOutPW = "-AcceptEula -i -h -u $($user) -p ******** ""$($(get-location).Path)\$($InstallFile)"" $($InstallParameters)"
LogIt -message ("Calling: $PSExec with argument: $ArguemntsWithOutPW") -component "Main()" -type 1
$Return = Start-Process $PSExec -arg $Arguments -PassThru -wait
$Return.HasExited | Out-Null

There is some more script, but I don’t think it is relevant for you to understand :slight_smile:

The user and password is fictive.

I want to be able to have a command in PSADT that will execute the PsExec and install the Application as that user.

Is that possible?

No one have any clue how to do this?

It’s possible to do this with the code that you’ve posted, however, you probably want to have a look at the “Execute-Process”. In the code below, I’ve specified the $dirFiles variable for the path (as you should put your installation files in the “Files” sub-folder and this is where the $dirFiles points to), but the Execute-Process defaults to this, so they could be left out. The Toolkit Help Console is really useful for command reference and the AdminGuide has a list of all the variables used on pages 33-37.

Anyway, does the below help (untested code)?


$InstallParameters="/Q /C C:\Temp\GoogleChrome.xml"

$user = "$env:computername\SVC_StoreUser"

$password = "P@ssw0rd"

Execute-Process -Path "$(dirFiles)\psexec.exe" -Parameters "-AcceptEula -i -h -u $($user) -p $($password) ""$(dirFiles)\$($InstallFile)"" $($InstallParameters)"

Hi Jonathan,

Thank you for spending time helping me. I appreciate.
I was working a bit on this earlier, and found out to use the Execute-Process as you told me, and that worked.

But I missed all the syntax with the parameters, so I will try that when getting back to work Monday.

I will let you know when I have tried that.
Have a great weekend

Hi Jonathan,

I tried to add your script to the package, but when running Deploy-Application.exe, I get following error?


I think I resolved it.
I removed () around DirFiles for both PsExec and for InstallFiles (GoogleChrome.exe) and it did fail. I’m trying to see if it works now.

$InstallParameters="/Q /C C:\Temp\GoogleChrome.xml"
$user = “$env:computername\SVC_StoreUser”
$password = “P@ssw0rd”

Execute-Process -Path “dirFiles\psexec.exe" -Parameters "-AcceptEula -i -h -u (user) -p ($password) “”$dirFiles$(InstallFile)"" ($InstallParameters)”

Sounds like you’ve got it sorted, but it’ll be PowerShell enumerating the variables within a string. You may need a backslash and an extra $…

Execute-Process -Path "dirFiles\psexec.exe" -Parameters "-AcceptEula -i -h -u (user) -p ($password) ""$dirFiles\$InstallFile"" $InstallParameters”

Let us know how you get on :slight_smile: EDIT: Just noticed that it may have been the forum that appears to have removed the backslash.

Hi Jonathan,

Thanks again. I have tested it manually so far, and that seems to work :slight_smile:

I will create the application in one of the SCCM Servers, and make the deployment from that. But as I do the manually installation as it will happen from SCCM, I believe it will work there as well.

I will let you know when tested.

Hello people and Jonathan,

I have now tested and verified it works as it should now!
Thanks a lot. You provided me the last couple of things so it works as it should now :slight_smile:

Always so nice when people take them time to help each other.

Happy new year and have a great day