Example from book by Jones & Hicks

Welcome Forums General PowerShell Q&A Example from book by Jones & Hicks

This topic contains 1 reply, has 2 voices, and was last updated by

9 months, 3 weeks ago.

  • Author
  • #101253

    Points: 370
    Rank: Contributor

    Hello Sir/Madam,

    I am stuck with the second of two examples on Page 96 (Chapter 8 – Objects)of this book Learn Windows Powershell in a Month of Lunches (3rd ed.). The second command, which is:
    Get-Process | Select-Object -property Name,ID,PD,VM | Convert-ToHTML | Out-File test2.html
    generates an error message that says: "Convert-ToHTML is not recognized as the name of a cmdlet, function ...".
    After several "closer examinations" of the example, I realized that it mis-spells "Convert-ToHTML": the correct syntax should be "ConvertTo-HTML". I have changed this post after discovering the reason for the error.
    Ramon Tan

  • #101263

    Points: 1,071
    Helping Hand
    Rank: Community Hero

    It's because this...


    .. is not a cmdlet in PoSH. It's a typo.

    Get-Command -Name *html* 
    CommandType Name           Version Source                      
    ----------- ----           ------- ------                      
    Cmdlet      ConvertTo-Html Microsoft.PowerShell.Utility

    When you run into messages the say X or Y is not valid, always look it up in the built-in help files.

    Here is a snippet I pulled together for such efforts. Just save it as a snippet in you PoSH snippets so you can bring it up as needed when looking up stuff.

    # Get parameters, examples, full and Online help for a cmdlet or function
    # Get a list of all functions
    Get-Command -CommandType Function | 
    Out-GridView -PassThru -Title 'Available functions'
    # Get a list of all commandlets
    Get-Command -CommandType Cmdlet | 
    Out-GridView -PassThru -Title 'Available cmdlets'
    # Get a list of all functions for the specified name
    Get-Command -Name '*ADGroup*' -CommandType Function | 
    Out-GridView -PassThru -Title 'Available named functions'
    # Get a list of all commandlets for the specified name
    Get-Command -Name '*ADGroup**'  -CommandType Cmdlet | 
    Out-GridView -PassThru -Title 'Available named cmdlet'
    # get function / cmdlet details
    (Get-Command -Name Get-ADUser).Parameters
    Get-help -Name Get-ADUser -Examples
    Get-help -Name Get-ADUser -Full
    Get-help -Name Get-ADUser -Online
    Get-Help about_*
    Get-Help about_Functions
    # Find all cmdlets / functions with a target parameter
    Get-Command -CommandType Function | 
    Where-Object { $_.parameters.keys -match 'credential'} | 
    Out-GridView -PassThru -Title 'Available functions which has a specific parameter'
    Get-Command -CommandType Cmdlet | 
    Where-Object { $_.parameters.keys -match 'credential'} | 
    Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'
    # Get named aliases 
    Get-Alias | 
    Out-GridView -PassThru -Title 'Available aliases'
    # Get cmdlet / function parameter aliases
    (Get-Command Get-ADUser).Parameters.Values | 
    where aliases | 
    select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'
    # All Help topics locations
    explorer "$pshome\$($Host.CurrentCulture.Name)"
    # Get any .NET types and their static methods from PowerShell. 
    # Enumerate all that are currently loaded into your AppDomain.
    [AppDomain]::CurrentDomain.GetAssemblies() | 
    foreach { $_.GetTypes() } | 
    foreach { $_.GetMethods() } | 
    where { $_.IsStatic } | 
    select DeclaringType, Name | 
    Out-GridView -PassThru -Title '.NET types and their static methods'
    # Instantiate the types using new-object and call instance methods. 
    # You can use get-member on an instance to get the methods on a type.

The topic ‘Example from book by Jones & Hicks’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort