Deploying a simple Powershell script

Comments

5 comments

  • Kris Powell

    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
    Comment actions Permalink
  • David Cunningham

    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
    Comment actions Permalink
  • David Cunningham

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

    0
    Comment actions Permalink
  • Kris Powell

    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
    Comment actions Permalink
  • Kris Powell

    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
    Comment actions Permalink

Please sign in to leave a comment.