how i can see powershell module methods Source code

This topic contains 2 replies, has 2 voices, and was last updated by  Prakash Murugesan 2 years, 1 month ago.

  • Author
  • #38484

    Prakash Murugesan

    How I can see source code of functions that are included in third party PowerShell module?

    I want to see code for Get-CMSoftwareUpdate (this command is from sccm powershell module)

  • #38485

    Dave Wyatt

    Depends on how the command was written. You've got three main types:

    – PowerShell functions. These are easy, since the function "is" the source code. You can do something like this to open the file up in the ise, if the command is a function: powershell_ise (Get-Command Get-CMSoftwareUpdate).ScriptBlock.File

    – Cmdlets. These are .NET classes, usually written in C#. Unless the source code is open-source, you can't get its original form, but you can decompile back to a somewhat-readable C# file using free tools such as ILSpy or DotPeek. If it's a cmdlet, you can find the file that needs to be decompiled like this: (Get-Command Get-CMSoftwareUpdate).ImplementingType.Assembly.Location

    – CIM commands. These are auto-generated PowerShell wrappers around WMI classes; they're generated from cdxml files in the module directory. I'm not sure if there's an easy way to open an individual command's file, but once you know that's what you're dealing with, you can browse to the module's folder and open up the cdxml files to see what it's doing.

  • #38488

    Prakash Murugesan

    Dave really you are awesome. it helped me.

You must be logged in to reply to this topic.