Some basic PS questions:

This topic contains 7 replies, has 6 voices, and was last updated by  Moon Sund 3 weeks, 3 days ago.

  • Author
    Posts
  • #71951

    Peter
    Participant

    Sorry for these newbie questions but I am new to Powershell.

    1.) How do I find out my current Powershell version (under 64bit Win 7)?

    2.) What is the newest PowerShell version and how do I download it (not through MS update channel)?

    3.) Do PowerShell script files have a certain file extension which (when double clicked) will be executed automatically (similar to traditional *.bat files)?

    4.) If I start powershell from START menu a certain start path is shown.

    Is there a way to adjust this path to another directory? (or even better automatically to the last used)?

    Thank you

    Peter

  • #71954

    Olaf Soyk
    Participant

    Peter,

    welcome to the brighter world of Powershell scripting. 😉 But let me ask something first: Are you familiar with the concept of internet search engines?

    1.) How do I find out my current Powershell version (under 64bit Win 7)?

    You open a Powershell console or a Powershell ISE and "evaluate" the following variable like this:

    $PSVersionTable

    Tip: You can start typing "$PSV" and hit Tab – Powershell will extend the variable to its proper name for you.

    2.) What is the newest PowerShell version and how do I download it (not through MS update channel)?

    Something about 5.1. ..... it even depends on the Windows version you're working with

    3.) Do PowerShell script files have a certain file extension which (when double clicked) will be executed automatically (similar to traditional *.bat files)?

    Yes. "*.ps1" BUT You cannot run Powershell scripts with a double click. If you need to do something like this you can use shortcuts with the complete command line to run Powershell console including the script path.

    4.) If I start powershell from START menu a certain start path is shown. ...

    Yes. The Powershellest way to set your environment to your needs would be to create a profile.

    Have a lot of fun!

    • #82163

      Moon Sund
      Participant

      Yes. "*.ps1" BUT You cannot run Powershell scripts with a double click. If you need to do something like this you can use shortcuts with the complete command line to run Powershell console including the script path.

      This is a whole new point for me, many thanks!

      Could you please explain more on whole ecosystem including powershell hosts and restricted language endpoints.
      What it all has to do with Powershell as new default Windows CLI?

    • #82166

      Moon Sund
      Participant

      This this seems related.
      please help getting it all together

    • #82438

      Pradeep Arora
      Participant

      Please watch the Microsoft Virtual Academy (mva.microsoft.com) Powershell videos on getting started and then advanced tools & scripts, you will get a lot of the creator's philosophy and reasoning behind why things are the way they are.

    • #83158

      Moon Sund
      Participant

      Thank you for advice.
      I do know these resources and have watched them partially, also read a lot of the leanpub and powershell.org.
      But apparently still missing some important points, such as one mentioned above.

      I would like getting to a wider context, such as on OS, .NET and powershell itself execution and managing environments. This my demand is absolutely practical.

      In addition, I hope to learn of the theoretical computer science/programming language view on all the powershell machinery, but what I've seen before from general scientists is (unfriendly) ignorance of the matter.
      Monad was rebranded due to ease of acceptance of wide public, Don Jones' annotations on its 'manifesto' are practical. I miss the theoretical point of view.

  • #72055

    figueroa2david
    Participant

    Hopefully these will be a little clearer..

    2. PS 5.1 is the most current (since you did mention Windows 7 x64) – you can download it from Microsoft https://msdn.microsoft.com/en-us/powershell/wmf/5.1/install-configure

    3. No — you can't automatically launch the powershell scripts like batch files. You have to call them from powershell, or a batch file, or a shortcut file etc. Your command line to use would be powershell.exe -file , and you would use that for your shortcut, batch file, etc.

    4. You will want to create a powershell profile — the profile is just a powershell script, but it has a specific name and exists in a specific location. Check this link: https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/. But, since you want to have it remember the last location, then you need to specifically record the path.
    Something like this might accomplish what you are looking for (in your Powershell profile).. it's basically 2 phases. at start up and at closing..

    Something like this might work.. (might need to be tweaked)..
    The first 2 lines handle changing the path when you first start powershell
    The third line creates an event watcher looking for the powershell host to close, and when it closes gracefully, it stores the value in the root of the user's profile (paths could be changed).

    $LastUsedPath = Get-ItemProperty -path HKCU:\ -name LastUsedPath
    if ($LastUsedPath) { set-location $LastUsedPath }
    Register-EngineEvent PowerShell.Exiting -Action { set-itemproperty -path HKCU:\ -name LastUsedPath -value $PWD }
    

    David F.

    • #72067

      Olaf Soyk
      Participant

      Regardless of whether I would consider this approach as a little bad style or not. I suspect your code snippet would not work right away. At least not without a little modification or preliminary work.
      Because the regsitry key value you mentioned is not a standard on Windows it does not exist until you create it. So either you have to create it first or you have to add a "-Force" to the "Set-ItemProperty" cmdlet in your snippet.
      And on top of that – your approach would potentially cause Powershell to start every time with another location. I'm sceptic that it is what Peter asked for.
      Até logo 😉

You must be logged in to reply to this topic.