The Basics of PowerShell Day By Day

  • Comments posted to this topic are about the item The Basics of PowerShell Day By Day

  • Get-Module only lists the currently loaded modules, if you want a list of all installed modules you need to use 'Get-Module -ListAvailable'.

  • Thank you very much for the very informative article!  I really gained an understanding from the way you explain things.  I would like to understand why we see what we do in the output.  For example, Get-Service | Where-Object {$_.Name -like "SQL*"}... lists the Status, Name, DisplayName in the output.  As I understand it, it shows 3 properties of the System.ServiceProcess.ServiceController object.  Is the decision being made by the Get-Member?  or Where-object?

    I look forward to reading a lot more from you.  I appreciate you sharing your knowledge.

  • Thank you for the informative basic explanation of PoSH. I think that this explanation will help those readers not familiar with it to have a deeper understanding the basics of the syntax and the functionality. Great job!

  • The decision which properties are shown by default for get-service is done by an XML file called 'types.ps1xml' in C:\Windows\System32\WindowsPowerShell\v1.0

    In this file you will find the following XML block:



    <Type>
    <Name>System.ServiceProcess.ServiceController</Name>
    <Members>
    <MemberSet>
    <Name>PSStandardMembers</Name>
    <Members>
    <PropertySet>
    <Name>DefaultDisplayPropertySet</Name>
    <ReferencedProperties>
    <Name>Status</Name>
    <Name>Name</Name>
    <Name>DisplayName</Name>
    </ReferencedProperties>
    </PropertySet>
    </Members>
    </MemberSet>
    <AliasProperty>
    <Name>Name</Name>
    <ReferencedMemberName>ServiceName</ReferencedMemberName>
    </AliasProperty>
    <AliasProperty>
    <Name>RequiredServices</Name>
    <ReferencedMemberName>ServicesDependedOn</ReferencedMemberName>
    </AliasProperty>
    <ScriptMethod>
    <Name>ToString</Name>
    <Script>
    $this.ServiceName
    </Script>
    </ScriptMethod>
    </Members>
    </Type>

    The columns that are selected when you don't choose explicitly which columns you want are in the propertyset 'DefaultDisplayPropertySet'

  • There are many editors available for Powershell - and the default Windows Powershell ISE works quite well for basic scripting.  It allows writing the script and executing command line and even allows running of selected code from the editor window.

    On Windows 10 - you can also set Powershell to replace the old command prompt so any time you open a 'command' window it will open Powershell.

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • I liked your article, and it sparked a little more research on my part. I remembered reading something about Filtering Objects vs Where-Object, and wanted to know what is the deference. It may be a good candidate for 'basics'...

    Found this article: https://sid-500.com/2017/06/24/powershell-filtering-objects-vs-where-object/ by Patrick Gruenauer who said filter is better.

    Thanks for sharing Frank

    David

    • This reply was modified 4 years, 4 months ago by  dsully.
  • Filter vs where-object:

    Filter = SELECT only columns you need WHERE only rows you need

    Where-Object: SELECT * without WHERE, and then filter in the application

  • ildjarn.is.dead wrote:

    Get-Module only lists the currently loaded modules, if you want a list of all installed modules you need to use 'Get-Module -ListAvailable'.

    Thanks for this, I keep forgetting about that switch.

    Apologies for the delay, I didn't realize I had comments on the article until Steve sent me a note today.

  • ddavis-917060 wrote:

    Thank you very much for the very informative article!  I really gained an understanding from the way you explain things.  I would like to understand why we see what we do in the output.  For example, Get-Service | Where-Object {$_.Name -like "SQL*"}... lists the Status, Name, DisplayName in the output.  As I understand it, it shows 3 properties of the System.ServiceProcess.ServiceController object.  Is the decision being made by the Get-Member?  or Where-object?

    I look forward to reading a lot more from you.  I appreciate you sharing your knowledge.

    The display only shows some fields by default. A few comments below talk about the Select-Object v Where-Object. There Where-Object gets all fields, but then filters based on the criteria.

    Apologies for the delay, I didn't realize I had comments on the article until Steve sent me a note today.

  • Jeffrey Williams wrote:

    There are many editors available for Powershell - and the default Windows Powershell ISE works quite well for basic scripting.  It allows writing the script and executing command line and even allows running of selected code from the editor window.

    On Windows 10 - you can also set Powershell to replace the old command prompt so any time you open a 'command' window it will open Powershell.

     

    Thanks for the note. I should have covered the ISE, but I've gotten used to using the cmd and VS Code. I'll add that in the next article. I'll also explain how to set the default cmd shell

    Apologies for the delay, I didn't realize I had comments on the article until Steve sent me a note today.

  • dsully wrote:

    I liked your article, and it sparked a little more research on my part. I remembered reading something about Filtering Objects vs Where-Object, and wanted to know what is the deference. It may be a good candidate for 'basics'...

    Found this article: https://sid-500.com/2017/06/24/powershell-filtering-objects-vs-where-object/ by Patrick Gruenauer who said filter is better.

    Thanks for sharing Frank

    David

    I'll had to test this, but I'm not sure all the cmdlets I use have a filter parameter that's as useful as Where-Object.

     

  • Nice quick summary.  I liked it a lot.  Looking forward to the next one.

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply