none
showing the definition field in powershell windows RRS feed

  • Question

  • Hi,

    I am a newbie in Poweshell. I watched some video  tutorials and now I'm trying to begin some work in PS. My first problem is that I can't see the definition field in my Powershell window.

    for example:

    in the tutorial it is showing like this:

    PS C:\> get-command -Name *..*

    CommandType   Name    Definiton

    in my Powershell window I have:

    PS C:\> get-command -Name *..*

    CommandType   Name    ModuleName

    As you can see, I have the ModuleName field instead of Definition filed. This is just an example because this field is never showed.

    Please tell me what I need to do. 

    Thank you.

    Monday, May 12, 2014 7:54 AM

Answers

All replies

  • Are you looking something like this?

    Get-Command * | Select Name , Module , Definition


    Regards Chen V [MCTS SharePoint 2010]

    Monday, May 12, 2014 8:03 AM
  • This will be in readable format

    Get-Command Get-Service | Select -Property Name , Module , Definition | fl


    Regards Chen V [MCTS SharePoint 2010]

    Monday, May 12, 2014 8:05 AM
  • thanks, but I need something to be permanent, because I need to see the definition field anytime I run the get-command action like in the tutorials..

    it is possible to do something like that:

    PS C:\> Get-Command Notepad -All | Format-Table CommandType, Name, Definition CommandType Name Definition ------------------------- Application notepad.exe C:\WINDOWS\system32\notepad.exe Application NOTEPAD.EXE C:\WINDOWS\NOTEPAD.EXE

    and then to save this line "Format-Table CommandType, Name, Definition" to a profile file?

    • Edited by reddyBo Monday, May 12, 2014 8:33 AM
    Monday, May 12, 2014 8:30 AM
  • Hi Reddy,

    where there is a will, there is a way. It's bad practice (and by the heavens, please get rid of this solution once you're done with those tutorials!) but you can overwrite the Get-Command cmdlet with a function.

    You edit your profile by calling
    notepad $profile

    There you place the following (very rough, I don't clean up things like that) function:

    function Get-Command
    {
    	Param (
    		$String
    	)
    	
    	$ps = [Powershell]::Create()
    	$ps.AddCommand("Get-Command") | Out-Null
    	$ps.AddParameter("name", $string) | Out-Null
    	$ps.AddParameter("all", $true) | Out-Null
    	$ps.Invoke() | FT CommandType, Name, Definition -AutoSize
    	$ps.Dispose()
    }

    Now, when you start Powershell and call Get-Command, you will call this function instead of the official cmdlet. Please note however that this limits you to very basic parameters unless you go ahead and customize it for yourself to add more parameters.

    If you want to permanently rid yourself of this function, just open your profile again and delete it.
    If you want to temporarily disable it until next Powershell restart, enter this command:
    Get-Item function:\Get-Command | Remove-Item

    Cheers,
    Fred

    PS.: Please note that Format-Table has an Alias - a shorthand, if you will - that's faster to type: FT
    Also, if you don't mind a bit stuff cluttering your screen you can use the Format-List * command (fl *), which will show all properties the object has.


    There's no place like 127.0.0.1

    Monday, May 12, 2014 10:12 AM
  • Thank you very much guys, I'm grateful
    Monday, May 12, 2014 12:09 PM