PS ~ Get-Member

Discussion in 'Scripting' started by Dark Dinosaur, Nov 17, 2022.

  1. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,729
    5,174
    120
    #1 Dark Dinosaur, Nov 17, 2022
    Last edited: Nov 17, 2022
    since i start read & learn about PS
    i didn't understand things too much ...
    the basic things, missing function, variables
    until I read this article about Get-Member thing

    Get-Member
    Gets the properties and methods of objects.
    https://learn.microsoft.com/en-us/p...rshell.utility/get-member?view=powershell-5.1

    so basically, instead of breaking your head how to get information from function
    you only type this, and 90% its done
    Code:
    @(Func) | get-member
    
    so i break my f* head how to get file version information
    spend f* few hours, and by check with get-member
    just found out - .VersionInfo option -> .FileVersion is available
    no -> select .. | select | more s**t .. only short line like this
    Code:
    @(Get-ItemProperty -lit @(Join-Path -Path $env:ProgramFiles -ChildPath 'myapp\myapp.exe')).VersionInfo.FileVersion
    Another example

    get-service | get-member
    you have property -> Name
    so instead of -> | select Name
    we can do this -> @(get-service).Name
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,729
    5,174
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Dark Why doing so much hard work as you can simply use short code + Alias for full Func :
    Code:
    Powershell -C "(GP '%ProgramFiles%\7-Zip\7zFM.exe').VersionInfo.FileVersion"
    
    i do use this :
    Code:
    echo 7-Zip Version & Powershell -C "(GP '%ProgramFiles%\7-Zip\7zFM.exe').VersionInfo.FileVersion"
    
     
  4. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,729
    5,174
    120
    I didn't go so far into Alias
    but when using this,
    I starting forget the real func name :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Hmm OK ;)
    you dont have to go that much far :

    Powershell -C "Get-Help Function-You-Query-For" thats all .
    suppose Powershell -C "Get-Help Get-ItemProperty" will result :

    Code:
    NAME
        Get-ItemProperty
    
    SYNTAX
        Get-ItemProperty [-Path] <string[]> [[-Name] <string[]>] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Credential <pscredential>] [-UseTransaction]  [<CommonParameters>]
    
        Get-ItemProperty [[-Name] <string[]>] -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Credential <pscredential>] [-UseTransaction]  [<CommonParameters>]
    
    
    ALIASES
        gp