Let’s take a fairly common task that many system administrators face: creating shortcuts on all user desktops.
PDQ Deploy and PowerShell go together like eggs and bacon. There are so many things that PowerShell can do by itself, but when combined with the power of PDQ Deploy, the sky becomes the limit for what’s possible.
We’re going to assume that PDQ Deploy and PowerShell are already installed.
Using PowerShell to Create a Shortcut on All User Desktops
Here’s a quick script to create a shortcut to Notepad and put it on the public desktop.
# Create a Shortcut with Windows PowerShell
$TargetFile = "$env:SystemRoot\System32\notepad.exe" $ShortcutFile = "$env:Public\Desktop\Notepad.lnk" $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $Shortcut.Save()
Let’s save this into a powershell script file (.ps1 file). For this example, I simply called my file, “Super SysAdmin Script.ps1,” though I would suggest a more appropriate name for your environment.
Using PDQ Deploy to Run PowerShell (.ps1) Scripts Remotely
Here’s the general rundown for how to configure a package in PDQ Deploy to deploy your newly-created PowerShell script. I’m going to use screenshots where possible, but you should definitely check out the PDQ Deploy videos. Here’s one of our awesome videos that includes how to add PowerShell scripts (.ps1 files) to a package – link to video.
They’re very helpful and provide lots of information, plus Shane has an awesome beard that some say give him magical powers.
Creating a package using our new script
Click New Package button
Name your package
Click on Step 1 within the package (it’s an Install Step)
Navigate to the location of the install file – the script in our example
Save your package
Here’s an animated example:
Deploying to Your Workstations
1) Click Deploy Once Button
2) Add target machines manually or via the Choose Targets button
(both options shown)
Adding machines manually is great for a quick deployment, but for more flexibility and power, you can use this into our other product PDQ Inventory. You can make collections to dynamically deploy to machines based off of different sets of criteria.
Additionally, with the Pro and Enterprise versions of the software, you can set up packages to run on a schedule, automatically retry failed machines, email you the results, use Wake-On-LAN, and much more. You can check out the differences.
3) Verify your deployment
Ta da! Like magic, all users on SomeComputer should now have a shortcut to Notepad on their desktop.
One thing to keep in mind when using PowerShell with PDQ Deploy is that when PDQ Deploy runs a PowerShell script, it is only going to show whether or not the script was able to execute. In order to see more detailed information (errors or otherwise), you’ll have to dive deeper into the output of your deployment. As a quick example to demonstrate this, I have created a package that deploys the following PowerShell as a script.:
Wirte-Host "Here's an example..."
Notice that I have purposefully misspelled the cmdlet Write-Host for the purpose of generating an error.
When I deploy the package to a target, it shows that the deployment was successful. Upon a more detailed investigation, I can see that the Output Log indicated an error.
Be sure to look at the output log whenever you have unexpected results. It can really help narrow down the causes for various issues.
I hope this gives you an additional way to utilize PowerShell in your environments.
PDQ Deploy is a powerful tool that allows you to use PowerShell (and much more) in efficient and creative ways. I’m sure you’ll find many exciting features that you’ll fall in love with as well.
Kris was an employee at PDQ.