PowerShell snap-ins

  • Hi,

    I'm reading through a book on PowerShell and tried the examples about finding the available cmdlets for a snap-in.

    What seems odd is that even though the book shows output for the commands, the only one that returns results for me is the Core snap-in listing:

    Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "core"}

    The others, for example, return no results in my PowerShell session.

    Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "host"}

    Does anyone know why this is? Do I have to load the other snap-ins for them to show up when I issue those commands (PowerShell.Management, Security, etc.)?

    Thanks for any help!

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • The assumption is that you will not have any non-core snap-ins loaded at startup. On my machine:

    [font="Courier New"]PS C:\Users\Orlando> Get-Command -commandtype cmdlet | select PSSnapin -Unique

    PSSnapIn

    --------

    Microsoft.PowerShell.Core

    PS C:\Users\Orlando> Add-PSSnapin -Name SqlServerProviderSnapin100 -ErrorAction SilentlyContinue

    PS C:\Users\Orlando> Get-Command -commandtype cmdlet | select PSSnapin -Unique

    PSSnapIn

    --------

    Microsoft.PowerShell.Core

    SqlServerProviderSnapin100[/font]

    What does this say for you in a new session?

    Get-Command -commandtype cmdlet | select PSSnapin -Unique

    What about after importing a non-core snap-in?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Thanks for your response!

    When I run this command in a new session:

    Get-Command -commandtype cmdlet | select PSSnapin -Unique

    I get this:

    PSSnapIn

    --------

    Microsoft.PowerShell.Core

    PS C:\Windows\system32>

    Maybe I just need to manually load whatever snap-ins I want to use or test out?

    Thanks again.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • webrunner (6/28/2013)


    Maybe I just need to manually load whatever snap-ins I want to use or test out?

    Yep. For oft used snap-ins you can edit your Profile so they are auto-loaded into every session. Just make sure that if you deploy code that your script explicitly loads it, or you alter the Profile on the server too, else your script won't have the necessary bits to do its work.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (6/28/2013)


    webrunner (6/28/2013)


    Maybe I just need to manually load whatever snap-ins I want to use or test out?

    Yep. For oft used snap-ins you can edit your Profile so they are auto-loaded into every session. Just make sure that if you deploy code that your script explicitly loads it, or you alter the Profile on the server too, else your script won't have the necessary bits to do its work.

    Great, thanks again for your help.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

Viewing 5 posts - 1 through 4 (of 4 total)

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