Run Script from SCCM

New Contributor

I am a novice at PowerShell. I have a request to run a script from SCCM to install a list of printer drivers. Script is as follows...

 

# Ricoh Universal Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\Universal Print Driver ver4_27\disk1" -Recurse -Filter "*.inf" |

ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
# Ricoh SP3410dn Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP 3410DN\PCL6\DISK1" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
# Ricoh SP3510dn Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP 3510DN\PCL6\DISK1" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
# Ricoh SPC232dn Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP C232DN\PCL6\DISK1" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
# HP T1300 Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\HP\T1300 PS Server 2016\win_x64_ps3_drv\win_x64_ps3_drv" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
# Zebra ZDesigner GX420t Print Driver
Get-ChildItem "\\server\d$\Print_Drivers\Other\Zebra\ZD5-1-16-7110\ZBRN" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }

 

I can run this script locally on a machine & it runs fine, takes about 90 seconds to complete.

 

When I create an application for it in SCCM & deploy it, its like it doesn't have time to complete the installs before PowerShell shuts down. Then the app shows as failed in Software Center.

 

How do I make it wait to finish running the script before closing out PowerShell?

5 Replies

@John Andrews 

What is the command line you are using in your deployment?  Are you using Start /wait to ensure the command stays open while the script runs?

 

James

@J Mymryk 

Thanks for the reply. I am just starting out with working in PowerShell.

 

This is the command line:

powershell.exe -executionpolicy bypass -file ".\Filename.ps1"

 

Where would the Start /wait go. 

 

For details on how start works, from a command prompt run start /?
or: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/start
basically run @start /wait "Command line" <parameters>
This will keep the command window open until it completes.

@J Mymryk 

Thanks again. So it would look something like this?

 

@start /wait powershell.exe -executionpolicy bypass -file ".\File.ps1"

Sorry I haven't been in the forum for a bit but yes that looks about right but remove .\ for the file as it may not determine the location correctly.