The Basics of PowerShell Day By Day

  • FrankDolan77

    SSC Veteran

    Points: 279

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

  • ildjarn.is.dead

    Right there with Babe

    Points: 776

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

  • ddavis-917060

    Newbie

    Points: 4

    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.

  • kslentz

    Say Hey Kid

    Points: 688

    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!

  • ildjarn.is.dead

    Right there with Babe

    Points: 776

    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'

  • Jeffrey Williams

    SSC Guru

    Points: 88658

    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
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

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

  • dsully

    SSC Rookie

    Points: 29

    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 1 month, 1 week ago by  dsully.
  • ildjarn.is.dead

    Right there with Babe

    Points: 776

    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

  • FrankDolan77

    SSC Veteran

    Points: 279

    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.

  • FrankDolan77

    SSC Veteran

    Points: 279

    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.

  • FrankDolan77

    SSC Veteran

    Points: 279

    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.

  • FrankDolan77

    SSC Veteran

    Points: 279

    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.

     

  • dth6

    SSC Enthusiast

    Points: 122

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

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

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