Install exe through powershell script and SCCM

Hi All. I am trying to install a application via SCCM. The script is running fine except for my last line to install the application.


I have tried a bunch of things but i think that my issue is that its either not reading the switches or can’t find the script path.

# Get Script Path
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
# Install Android Studio
"$scriptPath\android-studio-ide-182.5314842-windows.exe /S /Allusers"
# Extract SDK Files
Expand-Archive -Path "$PSScriptRoot\" -DestinationPath "C:\" -Force

# Add envro vars
$AddPath ="C:\AndroidSDK\platform-tools;C:\AndroidSDK\tools"
$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
$OldPath = (Get-ItemProperty -Path "$Reg" -Name PATH).Path
$NewPath= $OldPath + ';' + $AddPath
Set-ItemProperty -Path "$Reg" -Name PATH –Value $NewPath


I have tried a few different things like $PSScriptRoot but when running through SCCM it doesn’t install. I also tried running with start-process and the -argumentlist parameter but that also fails.

I’m not getting anything in the event log and the SCCM log says success (as the script is running)


Anyone know what i’m doing wrong>

To begin with it looks like you need to change line #5 to:

[pre]& “$scriptPath\android-studio-ide-182.5314842-windows.exe /S /Allusers”[/pre]

The ampersand character is a “call operator” in PowerShell. See Call operator - Run - PowerShell - It tells the PowerShell engine to execute the string provided. Let me know if that fixes the issue. As you had the line written all it is doing is returning the string value as output.

The alternative is to use Start-Process such as:

[pre]Start-Process -FilePath “$scriptPath\android-studio-ide-182.5314842-windows.exe” -ArgumentList “/S”,“/AllUsers” -Wait[/pre]

The only other comment I have (from learning the hard way) is that $PSScriptRoot only exists in PowerShell 3 and above. If you’re managing SCCM clients that still only have PowerShell 2 you should default to using the method you are using to assign the $scriptPath variable on line #3.

This should work:

& $scriptPath\android-studio-ide-182.5314842-windows.exe /S /Allusers

I think I might still have some clients with PS2. That is most likely why it wasn’t working on all of them.

I had tried like this which seemed to work but only on a few again most likely due to the older version.

# Get Script Path
$AndroidStudioInstaller = "$($PSScriptRoot)\android-studio-ide-182.5314842-windows.exe"
$InstallerArguments = "/S /Allusers"
start-process $AndroidStudioInstaller $InstallerArguments

The ‘&’ was indeed what I needed to get it to deploy. I should have passed it to get-member then I would have (hopefully) noticed that it was a string.