Remote Windows automation scripting: PowerShell, VBScript, batch files

brock profile
Brock Bingham|October 31, 2022
Product 1
Product 1

Scripts have become an essential part of the sysadmin toolkit. From simple one-liners to complex automation novellas containing enough commands to make the hosts of the PowerShell Podcast blush, if you can imagine it, you can probably script it. However, while scripts can be widely powerful, executing them against your remote endpoints isn’t always as easy as it should be. SmartDeploy's computer imaging tool simplifies remote script execution, allowing you to run your PowerShell, VBScript, and batch files against all your Windows devices, no matter where they’re located.

Important: All Application Pack scripts are executed as the LOCALSYSTEM account and must be fully unattended — no user interaction required.

Download prebuilt script packages

SmartDeploy provides a selection of prebuilt script packages downloadable from the Application Pack Library. The packs are built and maintained by the SmartDeploy team and provide functionality such as shutting down computers, updating Group Policy, and activating Windows.

To download prebuilt script Application Packs:

  1. In the SmartDeploy Console, click Applications & Tasks.

  2. Click the + button, then click Download an Application Pack.

    Click Download an Application Pack

  3. Enter script into the search bar, and press Enter on your keyboard to return only the script Application Packs.

    Enter Script into the search bar to narrow down the results

  4. Select the Application Pack you wish to download, then click Download. You can download as many Application Packs as you need. When finished, click Close.

Once you’ve downloaded the Application Packs, you will find them in your Applications & Tasks workspace.

Viewing scripts in the applications and tasks workspace

How to create custom, automated PowerShell tasks

As its name implies, PowerShell is a very powerful and robust scripting language. With it, sysadmins can interact with and manage almost every aspect of a Windows system. PowerShell is often used to automate both simple and complex tasks. In the example below, we’ll show you how to create an Application Pack to deploy a pre-built PowerShell Script (.ps1 file) called stop_chrome.ps1.

To build a custom PowerShell task in SmartDeploy:

  1. In the SmartDeploy console, click Applications & Tasks.

  2. Click the + button, then click Create an Application Pack.

    Creating an application pack

  3. At the welcome screen, click Next.

  4. In the Folder Path field, enter the path or browse out to the folder containing the PowerShell script.

  5. In the Executable Path field, enter the path or browse to the PowerShell script.

    Enter the path to the script

  6. Click Next.

  7. Enter your Application Pack details.

  8. Change your Pack Type to Script, then click Next.

    Enter the application pack details

  9. At the Installation Task window, a Command Preview is automatically generated, which will show you the command as it will actually be executed, passing it through powershell.exe with the -ExecutionPolicy Bypassargument added automatically. Review the command, add additional arguments if needed, then click Next.

    Review the generated command

  10. A warning prompt will inform you that the Arguments field is empty if you do not add additional arguments. This is because most silent/unattended commands do require additional arguments. However, in this case, because we are running a PowerShell script that we know will run silently, we do not need to add any arguments. Click Yes to proceed.

    A warning prompt will appear. Click Yes.

  11. Review or set the installed product display name. Ensure Version check is unselected. The Version check setting is designed to limit applications from installing on endpoints that already have the application installed. Since we are deploying a PowerShell script and not installing an application, this setting is not applicable. Click Next.

    Review or set the product display name and unselect version check

  12. Review the summary details, then click Next.

    Review the summary then click next

  13. Click Finish.

  14. Enter a file name for the Application Pack file, then click Save.

    Name and save the application pack

With the Application Pack saved, you will find it in the Applications & Tasks workspace in the SmartDeploy console. This pack is ready to be deployed and run against your remote endpoints, which we’ll cover in a later section.

How to create batch and VBScript tasks

If you prefer your scripts a little more old school, SmartDeploy still has you covered. SmartDeploy can remotely execute your favorite batch and Visual Basic scripts on your endpoints as long as they will run fully unattended. The process is almost identical to creating the custom PowerShell Application Pack. Here’s how it works:

  1. In the SmartDeploy console, click Applications & Tasks.

  2. Click the + button, then click Create an Application Pack.

  3. At the welcome screen, click Next.

  4. In the Folder Path field, enter the path or browse out to the folder containing the batch or Visual Basic script.

  5. In the Executable Path field, enter the path or browse to and select the script.

  6. Click Next.

  7. Enter your Application Pack details.

  8. Change your Pack Type to Script, then click Next.

  9. At the Installation Task window, a Command Preview is automatically generated, which will show you the command as it will be executed.

    1. Batch file commands should follow this command structure:

      cmd.exe /c “[ApplicationsFolder]\Application Pack\Files\YourBatchScript.bat”
      Batch file generated command

    2. Visual Basic script commands should follow this command structure:

      cscript.exe /b “[ApplicationsFolder]\Application Pack\Files\MyScript.vbs”
      Visual Basic script generated command

  10. A warning prompt will inform you that the Arguments field is empty if you do not add additional arguments. This is because most silent/unattended commands do require additional arguments. However, in this case, because we are running a script that we know will run silently, we do not need to add any arguments. Click Yes to proceed.

    A warning prompt will appear. Click Yes.

  11. Review or set the installed product display name. Ensure Version check is unselected. The Version check setting is designed to limit applications from installing on endpoints that already have the application installed. Since we are deploying a script and not installing an application, this setting is not applicable. Click Next.

  12. Review the summary details, then click Next.

  13. Click Finish.

  14. Enter a file name for the Application Pack file, then click Save.

How to deploy script packs with SmartDeploy

Now that our script packs are created, we can easily distribute them with SmartDeploy. Deploying script packs with SmartDeploy follows the same procedure as deploying an Application Pack. Here’s how it works:

  1. In the SmartDeploy console window, click on the Computer Management link.

    Click the Computer Management link

  2. Click All Computers.

    Click All Computers

  3. Select the computer you want to execute the script against, then click Deploy Application.

    Select the computer to deploy the script to

  4. Select either Local Network or Cloud Network depending on the location of your device, then click Next.

    Select either local network or cloud network depending on the location of your device

  5. Select the Application Packs or scripts you want to deploy, then use the arrow (->) button to add them to the deployment.

    Select the application pack to deploy

  6. Optionally, you can enable the user to defer the deployment and schedule it for a future date and time.

  7. Click Next.

  8. Enter the credentials necessary to access the selected file location, then click Finish.

    Enter the credentials to access the selected file location then click finish

  9. Click OK when asked to confirm the application deployment.

You can monitor the deployment status by clicking on the computer name of the device you deployed to.

Click on the device to monitor the deployment

Inside the computer details windows, scroll down and expand Message History. Here, you’ll find the deployment status.

Click message history to view deployment messages

How to incorporate scripts into your image deployments

Scripts aren’t just great for devices already in production; they’re also handy when imaging computers. SmartDeploy can automate your script deployments during the imaging process, which means one less thing for you to worry about.

SmartDeploy offers a couple of different ways to apply scripts to your image: Application Packs and postdeployment steps.

Let’s look at how to configure each option.

Application Packs

Adding existing Application Packs to an answer file is quick and easy with SmartDeploy. Just use the Answer File Wizard.

  1. In the SmartDeploy console, click on the Activities link.

  2. Click Reimage Devices.

  3. Click Create Answer File to launch the Answer File Wizard.

    Click Create Answer File

  4. With the Answer File Wizard open, advance through each screen, clicking Next to proceed until you reach the Application Packs window.

    Select the applications packs to add to the answer file

  5. Select the app and script packs you want to add, then click the arrow (->) to add them to the answer file.

    Use the arrow to add application packs to the answer file

  6. Click Next, and finishcreating the answer file.

Application and script packs that you include in this section of the answer file install and run after the Sysprep completes.

Post-deployment step

The next option is to save your scripts to your reference VM and then automate your scripts as a post-deployment step during the imaging process. This method gives you precise control over when your scripts execute during the imaging process.

  1. Launch the Answer File Wizard by clicking on Activities > Reimage Devices > Create Answer File.

  2. At the Answer File Wizard welcome window, click Advanced.

    Click advanced

  3. Click the Tasks tab.

  4. Click Add.

    Click Add to add a task

  5. Click the Phase drop-down menu, and select when you want the script to run. For help understanding the different phases, refer to the Answer File Tasks knowledge base.

  6. In the Command line field, enter the command to run your script. It should resemble the commands we used earlier in this article. Here is the command I would use to run a PowerShell script saved on the reference VM at C:\Scripts:

    powershell.exe -ExecutionPolicy Bypass -file "C:\Scripts\MyScript.ps1"
    Remote script command line

  7. Click OK when finished.

With your tasks added, finish running through the Answer File Wizard to complete the process. The resulting answer file is ready to automate your script executions during your future image deployments.

Simplify remote scripting

Scripts provide sysadmins with a level of functionality and flexibility necessary to complete many administrative tasks. However, running them against remote targets and during imaging can be a roadblock for many. This makes it difficult to carry out tasks like employee onboarding and offboarding when users are spread across multiple locations. SmartDeploy can help clear your roadblocks and get your scripts deployed to your endpoints no matter where they are. Take SmartDeploy for a test drive today, and see how it can simplify your workflows.

brock profile
Brock Bingham

Born in the '80s and raised by his NES, Brock quickly fell in love with everything tech. With over 15 years of IT experience, Brock now enjoys the life of luxury as a renowned tech blogger and receiver of many Dundie Awards. In his free time, Brock enjoys adventuring with his wife, kids, and dogs, while dreaming of retirement.

Related articles

Ready to get started?

See how easy device management can be. Try SmartDeployfree for 15 days — no credit card required.