How to get started with powershell

This topic contains 9 replies, has 7 voices, and was last updated by  postanote 1 month, 1 week ago.

  • Author
    Posts
  • #87929

    Matt
    Participant

    I have been looking at videos on Microsoft Virtual Academy, Pluralsight, blogs on the internet, PowerShell in a month of lunches, and I have picked up some valuable knowledge. Of course, the best way to learn something, is by doing it repetitively.

    The thing I am struggling with is where to start... can anyone recommend any scripts that they did when they were a complete beginner to get started? I would like some ideas of scripts I could create myself, and work from there to get better.

    I would like it to include functions, parameters, loops etc. so I'm targeting a lot of areas and I can improve my knowledge.

    Powershell seems like a great tool, and I would like to invest a lot of time into learning it (should have learnt it a few years ago) I just need some advice on where to start.

    thanks 🙂

  • #87932

    Jon
    Participant

    Anything you did via GUI, Google how to do it in the shell and do it that way.

    What is your job role? That would help with giving some more information

  • #87934

    Larry Keyes
    Participant

    Learn by doing. Find a project that you are interested in, and do it in Powershell. In my own case, I had a need to integrate various bits of an e-Commerce site, including Shopify (shop front end) Brightpearl (inventory), Warehouse, and credit-card processing, using REST-APIs. I knew I could have done it in Python or whatever, but I chose PS and managed to make substantial progress all while solving a series of sticky problems for my client. I'm now working with PS to automate manage of Office 365 for a branch office, which involves using PS to manage Exchange, o365, Azure, etc.

    • #88040

      Matt
      Participant

      Thank you all for the replies I didn't expect any!:)

      I work with office 365, azure, Intune, device management with configuration manager etc.

      There's so many options to learn, I just didn't know where to start with an easy project, building it up from there with powershell

      Matt

  • #87971

    postanote
    Participant

    1 – Everything you'd normally do at the DOS command prompt or VBScript, etc... start doing all that in the PowerShell ISE or PowerShell Console host or Visual Studio Code using the PowerShell Extension. Using only the normal DOS commands and then do the same with the cmdlets which do the same thing.

    Windows PowerShell equivalents for common networking commands (IPCONFIG, PING, NSLOOKUP)
    'blogs.technet.microsoft.com/josebda/2015/04/18/windows-powershell-equivalents-for-common-networking-commands-ipconfig-ping-nslookup'

    Know that interactive DOS commands don't work in the PowerShell ISE natively. You can make them work.

    See
    Using Windows PowerShell to run old command line tools (and their weirdest parameters)
    'blogs.technet.microsoft.com/josebda/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters'

    Note: Sometimes it is just easier to use the old DOS commands, even in PowerShell scripts, because though they may not be as flexible, they are more concise. I wrote a function that allows me to do this sort of stuff to avoid having to type all this stuff all the time.

    2 – Read the help files and about_* files, leverage the examples in the help files. Tweak the examples in the help files.

    3 – Use any Windows tool that will write the baseline code for you (which you can then tweak), such as the Windows Server 2012 ADAC console leveraging the PowerShell History Viewer.

    Active Directory Administrative Center: Getting Started
    'technet.microsoft.com/en-us/library/dd560651(v=ws.10).aspx'

    Active Directory Administrative Center
    'docs.microsoft.com/en-us/windows-server/identity/ad-ds/get-started/adac/active-directory-administrative-center'

    Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2
    'blogs.technet.microsoft.com/canitpro/2015/03/04/step-by-step-utilizing-powershell-history-viewer-in-windows-server-2012-r2'

    4 – Make a copy of...
    C:\Windows\System32\WindowsPowerShell\v1.0\Modules
    ... then, open the scripts, modules, functions in the default Windows PowerShell folder, in the PowerShell ISE or VSCode and review that's going on in them. Make a copy of them to play with and tweak. Also look for any other location that has *.ps* files, make a copy and review.

    5 – You can also directly look at many of the function code in PowerShell by doing this approach...
    Spying on Function Source Code
    'community.idera.com/powershell/powertips/b/tips/posts/spying-on-function-source-code'

    6 – Get real familiar with the PowerShell Snippets feature. press CTRL+J to see what is there.

    7 – Other MS produces and 3rdP vendor products, will show the PowerShell code they are using under the covers. As you use the Window GUI's pause a minute to look for the code on the screen and copy and save that off for your review.

    8 – Continue the video training, MVA, 'channel9.msdn.com/tags/PowerShell', YouTube, Plural, etc.

    9 – Keep a library of everything you find in a central location, OneNote, doc, or your own module for easy recall / research.

    • #88042

      Matt
      Participant

      Thank you, really helpful!!!

  • #87989

    Des Davies
    Participant

    Here's an idea, and one I am working on right now.

    Write a function to change the IP assigned to a record in DNS. A few notes:
    – The reverse record needs to be changed also
    – Take in to account the possibility of a change in subnet

    This is proving much trickier than it first appears. (Hint: The Set-DNServerResourceRecord cmdlet has some serious limitations)

  • #87998

    Ed Grant
    Participant

    Here is what I did. Pick something you do manually multiple times a day/week that annoys you and automate it. It doesn't matter if it saves you 5 seconds or 5 minutes, just pick one small thing that is relatively simple.

    One of my first ones was querying a CSV file for data. We have a login tracker in a CSV file. In order to match a machine with a user, we would open the CSV, do a CTRL + F and find the user or the machine name. Since there could be dozen of entries, it could take some time to find them all. So I wrote essentially a 1-liner that would take an input (a username or machine name) and return all instances of that login information.

    All told, I use that PowerShell module about 10-15 times a week and it saves me about 30 seconds each time. Multiply that by a little over 3 years and it adds up to quite a bit of saved time.

  • #88535

    Alex Aymonier
    Participant

    9 – Keep a library of everything you find in a central location, OneNote, doc, or your own module for easy recall / research.

    This!!!

    I personally use one ps1 file called Doodle and put my snipets in there i use all the time.

    • #88607

      postanote
      Participant

      Yeppers, that is the reason I suggest item #9. we consistently come across stuff, create stuff, share stuff, all is reusable.

      I have a single folder tree dedicated to scripts (since my early DOS days),
      BAT,CMD,VBS,WMIC,
      Monad,PoSH,VSC,VS(C#),SQL,
      HTA,JS,CS,HTML,CSS,JSON,
      Help,Docs,eBooks,Links,
      Tools,Add-ons and snippets.

      That library alone is 24+GB and growing (of course fully archived in multiple places, just in case). Every piece of code I've ever written, downloaded, copied, borrowed, etc. is in there since the 1980's.

      For my daily PoSH, efforts, I have a single ModuleLibrary.psm1 I created a long while back and update it all the time, which is set to import via my profile in ISE, VSCode, and Console host. It of course has grown a great deal over the years, so far over 5K+ lines of code and comments, etc.

      Other modules of in daily use and loaded with my profile.
      MS Module Browser = 2,170 modules in that remote library
      MS Script browser = 25,333 scripts in that remote library
      MS Script Analyzer
      MS Project Explorer

      PoSH ISE development – Tools / add-ons with a look...
      IseePack – Free
      'powershellise.com'

      IseSteroids (not free – but good stuff)
      'powertheshell.com/isesteroids'

      Of course adding these sort of things, will slow down the ISE startup, so be patient, it's well worth it.

You must be logged in to reply to this topic.