Forum Discussion

John Andrews's avatar
John Andrews
Copper Contributor
Nov 04, 2021

Run Script from SCCM

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

  • J Mymryk's avatar
    J Mymryk
    Copper Contributor

    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

    • John Andrews's avatar
      John Andrews
      Copper Contributor

      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. 

       

      • J Mymryk's avatar
        J Mymryk
        Copper Contributor
        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.

Resources