Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Deploying a simple Powershell script

I am trying to deploy and run a simple Powershell script to create a shortcut to the windows Calc app. PDQ says successful but NO icon;

I know the PS1 file works because I have run the script from my desktop and it created a shortcut to the calculator on my desktop

 

When I deploy to my own computer with the following settings I get successful but no icon

PS File is: MakeShortcut.ps1

# Create a Calculator Shortcut with Windows PowerShell
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Calc.lnk")
$Shortcut.TargetPath = "Calc"
$Shortcut.Save()

 

In PDQ:

Install file = C:\MakeShortcut.ps1

Command line: powershell.exe -executionpolicy unrestricted -File "MakeShortcut.ps1"

 

 

email me at dcunningham@tank-consultants.com




DeployCalc.PNG
0

Comments

5 comments
Date Votes
  • Hi David,

    Just so that I make sure that we're on the same page, are you intending to copy this shortcut to the desktop of all users of a workstation? 

    If you're intending to copy to the desktop of all users, I would suggest copying to the Public desktop of your workstation using $env:Public\Desktop in your script -- $Shortcut = $WshShell.CreateShortcut("$env:Public\Desktop\Calc.lnk").  This would be the easiest and most straightforward way to accomplish that.

    Alternatively, you can use .NET framework to get similar information from the System.Environment.SpecialFolder enumeration -- http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

    You can use these directly in Powershell.  An example of usage:

    To get the current User Desktop: [Environment]::GetFolderPath("Desktop")

    I hope this helps out.  Let us know if you have any further issues.

    Cheers,

    0
  • Kris P - Thanks for the suggestion, I will modify my script accordingly to : $Shortcut = $WshShell.CreateShortcut("$env:Public\Desktop\Calc.lnk")

    However I am still at a dilemma: How do I setup PDQ to run a PS1 when I deploy it? Tje users are all using Windows 7 which comes with a Powershell version installed from what I understand, therefore this should run I would think?

    0
  • Never mind KP - I see that your suggestion worked- thank you so much for helping me learn something new today - thanks again

    0
  • It sounds like you're deploying this to the desktop of all users, so modifying the script to use the public desktop should work.  I just tested that same script in my environment and it seemed to work just great.  It created the shortcut in C:\Users\Public\Desktop\

    Here's exactly what I have in my Powershell script:

    # Create a Calculator Shortcut with Windows PowerShell
    $WshShell = New-Object -ComObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$env:Public\Desktop\Calc.lnk")
    $Shortcut.TargetPath = "Calc"
    $Shortcut.Save()

     

    Did you get an error any anything?

    Cheers,

    0
  • Oops!  Looks like you beat me to it!  I'm glad to hear that you got it working.

    Let us know if you run into any further walls and we'll be happy to assist.

    Best of luck to you,

    0