No Get-InstanceID in Powershell 3.0

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Eric Bronnert Eric Bronnert 2 years, 3 months ago.

  • Author
    Posts
  • #18477
    Profile photo of Eric Bronnert
    Eric Bronnert
    Participant

    Hello everyone! Happy Wednesday!

    I have noticed around the forums and some replies I have gotten on some of my personal powershell issues that a command "Get-InstanceID" exists.
    I tried using this cmdlet myself to no avail..I have read that this cmdlet was introduced in 3.0...yet I in fact have powershell 3.0.

    It seems that my powershell doesn't have this command!

    What could the issue be?

    Thanks for your time

  • #18478
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I'm not familiar with the command, but *most* commands are not native to PowerShell. They are added in, usually as modules. That is almost always true when they relate to some external product. For example, Get-ADUser is not a native Windows PowerShell command; it comes with specific versions of the Windows operating system.

  • #18479
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    I assume you're referring to this thread: https://powershell.org/forums/topic/ambitious-yet-new/

    Get-InstanceID is a function whose code I posted in that forum thread. You would need to add it to your script, profile, or to a module:

    function Get-InstanceID
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
            [System.Int64[]]
            $EventID
        )
     
        process
        {
            foreach ($id in $EventID)
            {
                $maskedId = $id -band 0x3FFFFFFF
     
                $maskedId
                $maskedId -bor 0x40000000L
                $maskedId -bor 0x80000000L
                $maskedId -bor 0xC0000000L
            }
        }
    }
    
  • #18485
    Profile photo of Eric Bronnert
    Eric Bronnert
    Participant

    Oh, so you are creating the function with that code! Now I get it! I should of read the help on "function". I should of known this!

    Taken from the Learn Windows Powershell in a Month of Lunches book (second edition), page 38 Chapter 4

    "A function can be similar to a cmdlet, but rather than being written in a .NET language, functions are written in PowerShell's own scripting language."

    This answers my question! Thanks guys!

You must be logged in to reply to this topic.