Curious Array behaviour and Documentation analysis script

Discussion in 'Scripting' started by Neville Bagnall, Feb 3, 2006.

  1. First a question:

    Any idea whats happening here?

    MSH> get-command gci|foreach {$paramhelparray=((get-help
    $_).parameters|select -expand parameter|foreach {$_.name})}
    MSH> $paramhelparray[0] -eq "Path"
    True
    MSH> [System.Array]::indexof($paramhelparray,"Path")
    -1




    Discovered during development of following:

    filter check-docs {
    $paramarray=($_|select -expand parametersets|select -expand
    parameters|foreach {$_.name})
    $paramhelparray=((get-help $_).parameters|select -expand
    parameter|foreach {$_.name})

    # Add the ubiquitous parameters (OutBuffer isn't documented as one,
    but it occurs on all cmdlets)

    $paramhelparray+="Verbose","Debug","ErrorAction","ErrorVariable","OutVariable","WhatIf","Confirm","OutBuffer"
    $paramarray+="Verbose","Debug","ErrorAction","ErrorVariable","OutVariable","WhatIf","Confirm","OutBuffer"
    [email protected]()
    foreach ($parameter in $paramarray) {
    $found=$false
    foreach ($parameter2 in $paramhelparray) {
    if ($parameter -eq $parameter2) {
    $found=$true
    break
    }
    }
    if (-not $found) {
    $undocumented+=$parameter
    }
    }
    [email protected]()
    foreach ($parameter in $paramhelparray) {
    $found=$false
    foreach ($parameter2 in $paramarray) {
    if ($parameter -eq $parameter2) {
    $found=$true
    break
    }
    }
    if (-not $found) {
    $overdocumented+=$parameter
    }
    }
    $_|add-member -name UndocumentedParameters -type NoteProperty -value
    $undocumented|
    add-member -name InvalidDocumentedParameters -type NoteProperty -value
    $overdocumented
    }




    Which gives (somewhat cleaned up) output:

    MSH> get-command |check-docs|select
    name,UndocumentedParameters,InvalidDocumentedParameters|ft -wrap

    Name UndocumentedParameters
    InvalidDocumentedParameters
    ---- ----------------------
    ---------------------------
    add-content {Encoding} {}
    add-history {} {}
    add-member {} {}
    add-mshsnapin {} {}
    clear-content {} {}
    clear-item {} {}
    clear-property {} {}
    clear-variable {} {}
    combine-path {} {}
    compare-object {} {Key}
    convert-HTML {} {}
    copy-item {} {}
    copy-property {} {}
    export-alias {} {}
    export-clixml {} {}
    export-Console {} {}
    export-csv {} {}
    export-SecureString {} {}
    foreach-object {} {}
    format-custom {} {}
    format-list {} {}
    format-table {} {}
    format-wide {} {}
    get-acl {} {}
    get-alias {} {}
    get-childitem {} {}
    get-command {MshSnapin} {Snapin}
    get-content {Delimiter, Wait, Encoding} {}
    get-Culture {} {}
    get-Date {} {}
    get-drive {} {}
    get-eventlog {} {}
    get-help {} {}
    get-history {} {}
    get-host {} {}
    get-item {} {}
    get-location {} {}
    get-member {} {}
    get-mshsnapin {} {}
    get-process {} {}
    get-property {} {}
    get-service {} {}
    get-UICulture {} {}
    get-unique {} {}
    get-variable {} {}
    get-WMIObject {} {}
    group-object {} {}
    import-alias {} {}
    import-SecureString {} {}
    invoke-item {} {}
    match-string {FullName} {Path, Text}
    Measure-Object {} {}
    move-item {} {}
    move-property {} {}
    new-alias {} {}
    new-drive {} {}
    new-item {} {}
    new-object {} {}
    new-property {} {}
    new-SecureString {} {}
    new-service {} {}
    new-Timespan {} {}
    new-variable {} {}
    out-file {} {}
    out-host {} {}
    out-printer {} {}
    out-string {} {}
    parse-path {} {V2 - All}
    pop-location {} {}
    push-location {} {}
    read-host {} {}
    remove-drive {} {}
    remove-item {} {}
    remove-mshsnapin {} {}
    remove-property {} {}
    remove-variable {} {}
    rename-item {} {}
    rename-property {} {}
    resolve-path {} {}
    restart-service {} {}
    resume-service {} {}
    select-object {} {}
    set-acl {} {}
    set-alias {} {}
    set-AuthenticodeSignature {} {}
    set-content {Encoding} {}
    set-Date {} {}
    set-item {} {}
    set-location {} {}
    set-mshdebug {} {}
    set-property {} {}
    set-service {} {}
    set-tracesource {} {}
    set-variable {} {}
    sort-object {} {}
    start-service {} {}
    Start-Sleep {} {}
    start-transcript {} {}
    stop-process {} {}
    stop-service {} {}
    stop-transcript {} {}
    suspend-service {} {}
    tee-object {} {}
    test-path {} {}
    Time-Expression {} {}
    trace-expression {} {}
    update-FormatData {} {}
    update-typeData {} {}
    where-object {} {}
    Write-Error {} {}
    write-host {} {}
    write-progress {} {}






    These commands:

    convert-path
    get-AuthenticodeSignature
    get-credential
    get-PfxCertificate
    get-provider
    get-tracesource
    import-clixml
    import-csv
    Invoke-Command
    invoke-history
    out-default
    out-null
    Write-debug
    Write-Object
    Write-verbose
    write-warning



    seem to have a different help file structure as they cause:



    select-object : Cannot expand property "parameter" because it has nothing
    to expand.
    At line:3 char:49
    + $paramhelparray=((get-help $_).parameters|select <<<< -expand
    parameter|select name|foreach {$_.name})





    In the same vein:

    MSH> get-command |select name,parametersets

    Name ParameterSets
    ---- -------------
    add-content {__AllParameterSets}
    add-history {__AllParameterSets}
    add-member {__AllParameterSets}
    add-mshsnapin {__AllParameterSets}
    clear-content {__AllParameterSets}
    clear-item {__AllParameterSets}
    clear-property {__AllParameterSets}
    clear-variable {__AllParameterSets}
    combine-path {__AllParameterSets}
    compare-object {__AllParameterSets}
    convert-HTML {__AllParameterSets}
    convert-path {__AllParameterSets}
    copy-item {__AllParameterSets}
    copy-property {__AllParameterSets}
    export-alias {__AllParameterSets}
    export-clixml {__AllParameterSets}
    export-Console {__AllParameterSets}
    export-csv {__AllParameterSets}
    export-SecureString {Secure, Open}
    foreach-object {__AllParameterSets}
    format-custom {__AllParameterSets}
    format-list {__AllParameterSets}
    format-table {__AllParameterSets}
    format-wide {__AllParameterSets}
    get-acl {__AllParameterSets}
    get-alias {__AllParameterSets}
    get-AuthenticodeSignature {__AllParameterSets}
    get-childitem {Items, Names}
    get-command {CmdletSet, AllCommandSet}
    get-content {__AllParameterSets}
    get-credential {__AllParameterSets}
    get-Culture {__AllParameterSets}
    get-Date {net, unix}
    get-drive {__AllParameterSets}
    get-eventlog {LogName, List}
    get-help {__AllParameterSets}
    get-history {__AllParameterSets}
    get-host {__AllParameterSets}
    get-item {__AllParameterSets}
    get-location {Location, Stack}
    get-member {__AllParameterSets}
    get-mshsnapin {__AllParameterSets}
    get-PfxCertificate {__AllParameterSets}
    get-process {ProcessName, Id, Input}
    get-property {__AllParameterSets}
    get-provider {__AllParameterSets}
    get-service {Default, DisplayName, Input}
    get-tracesource {__AllParameterSets}
    get-UICulture {__AllParameterSets}
    get-unique {AsString, UniqueByType}
    get-variable {__AllParameterSets}
    get-WMIObject {query, list}
    group-object {__AllParameterSets}
    import-alias {__AllParameterSets}
    import-clixml {__AllParameterSets}
    import-csv {__AllParameterSets}
    import-SecureString {Secure, Open}
    Invoke-Command {__AllParameterSets}
    invoke-history {__AllParameterSets}
    invoke-item {__AllParameterSets}
    match-string {Object, File}
    Measure-Object {GenericMeasure, TextMeasure}
    move-item {__AllParameterSets}
    move-property {__AllParameterSets}
    new-alias {__AllParameterSets}
    new-drive {__AllParameterSets}
    new-item {pathSet, nameSet}
    new-object {Net, Com}
    new-property {__AllParameterSets}
    new-SecureString {__AllParameterSets}
    new-service {__AllParameterSets}
    new-Timespan {Date, Time}
    new-variable {__AllParameterSets}
    out-default {__AllParameterSets}
    out-file {__AllParameterSets}
    out-host {__AllParameterSets}
    out-null {__AllParameterSets}
    out-printer {__AllParameterSets}
    out-string {__AllParameterSets}
    parse-path {ParentSet, QualifierSet, NoQualifierSet,
    LeafSet, IsAbsoluteSet}
    pop-location {__AllParameterSets}
    push-location {Stack}
    read-host {__AllParameterSets}
    remove-drive {__AllParameterSets}
    remove-item {__AllParameterSets}
    remove-mshsnapin {__AllParameterSets}
    remove-property {__AllParameterSets}
    remove-variable {__AllParameterSets}
    rename-item {__AllParameterSets}
    rename-property {__AllParameterSets}
    resolve-path {__AllParameterSets}
    restart-service {Default, DisplayName, Input}
    resume-service {Default, DisplayName, Input}
    select-object {__AllParameterSets}
    set-acl {__AllParameterSets}
    set-alias {__AllParameterSets}
    set-AuthenticodeSignature {__AllParameterSets}
    set-content {__AllParameterSets}
    set-Date {To, Adjust}
    set-item {__AllParameterSets}
    set-location {Location, Stack}
    set-mshdebug {on, off}
    set-property {propertyMshObjectSet, propertyValueSet}
    set-service {__AllParameterSets}
    set-tracesource {optionsSet, removeAllListenersSet,
    removeFileListenersSet}
    set-variable {__AllParameterSets}
    sort-object {__AllParameterSets}
    start-service {Default, DisplayName, Input}
    Start-Sleep {Seconds, Milliseconds}
    start-transcript {__AllParameterSets}
    stop-process {Id, ProcessName, Input}
    stop-service {Default, DisplayName, Input}
    stop-transcript {__AllParameterSets}
    suspend-service {Default, DisplayName, Input}
    tee-object {File, Variable}
    test-path {ExistsSet, IsValidSet}
    Time-Expression {__AllParameterSets}
    trace-expression {expressionSet, commandSet}
    update-FormatData {__AllParameterSets}
    update-typeData {__AllParameterSets}
    where-object {__AllParameterSets}
    Write-debug {__AllParameterSets}
    Write-Error {NoException, WithException, ErrorRecord}
    write-host {__AllParameterSets}
    Write-Object {__AllParameterSets}
    write-progress {__AllParameterSets}
    Write-verbose {__AllParameterSets}
    write-warning {__AllParameterSets}



    highlights differences in the reflected attributes.

    Are these variations likely to be addressed as part of fit and finish at
    some point in the future, or are they designed in?

    Thanks,
    Neville.
     
    Neville Bagnall, Feb 3, 2006
    #1
    1. Advertisements

  2. Neville, your problem is that arrays which come out of a pipeline always
    contain MshObjects wrapping the original objects, even if this is not easy
    to see from within MSH. If you cast the array to "string[]", IndexOf should
    start working for you.

    MSH C:\temp\monad> get-command gci|foreach {$paramhelparray=((get-help
    $_).parameters|select -expand parameter|foreach {$_.name})}
    MSH C:\temp\monad> [System.Array]::indexof($paramhelparray,"Path")
    -1
    MSH C:\temp\monad> [System.Array]::indexof([string[]]$paramhelparray,"Path")
    0

    Thanks to BrucePay [MSFT] for his help with this.

    Regarding get-help: We know that there are some discrepancies with the
    current help. The help will be substantially rewritten in the coming
    months.

    Thanks,

    Jon Newman [MSFT]


     
    Jon Newman [MSFT], Feb 3, 2006
    #2
    1. Advertisements

  3. That sorted it.

    Thanks,
    Neville.
     
    Neville Bagnall, Feb 4, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.