Two cmdlets only being returned from Get-Command with wildcards via Invoke-Comma

This topic contains 2 replies, has 2 voices, and was last updated by  Kevyn 2 weeks, 6 days ago.

  • Author
    Posts
  • #78694

    Kevyn
    Participant

    This is a continuation of a previous post, but I thought I'd start it clean and explain what I've found.

    OK, riddle me this Batman.

    If I run the following bit of code (I've temporarily commented out the -ErrorAction parameter to see what results I would get):

    $Name = '*'
    $Module = '*'
    $Computer = 'localhost'
    $GCScriptBlock = {
                       $ConfirmImpactLevelExpr = @{
                                                    Name = 'ConfirmImpactLevel';
                                                    Expression = {$_.ImplementingType.GetCustomAttributes($True).ConfirmImpact}
                                                  }
                       Get-Command -Name Stop-* -CommandType Cmdlet -Module $Using:Module | Select-Object -Property Name,CommandType,ModuleName,$ConfirmImpactLevelExpr
                     }
    $ImpactLevelData = Invoke-Command -ComputerName $Computer -ScriptBlock $GCScriptBlock #-ErrorAction Stop
    

    I get the below errors on just these two cmdlets:

    The term 'Add-ClusteriSCSITargetServerRole' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
    included, verify that the path is correct and try again.
    + CategoryInfo : ObjectNotFound: (Add-ClusteriSCSITargetServerRole:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
    + PSComputerName : localhost

    The term 'Block-GPInheritance' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
    verify that the path is correct and try again.
    + CategoryInfo : ObjectNotFound: (Block-GPInheritance:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
    + PSComputerName : localhost

    Ok, now for the strange part. I focused on the Add-ClusteriSCSITargetServerRole cmdlet. Here is what I found.

    Note: Keep in mind, I'm doing this all on the same machine, same ISE.

    1. No matter what combination of parameters & wildcards I used, either the same error from above occurred when I tried to use Get-Command to look for the Add-ClusteriSCSITargetServerRole cmdlet, or the cmdlet was not in the resulting list.

    –Commands I tried:

    a. First Set:

    Get-Command -Name Add-ClusteriSCSITargetServerRole < --- Error occurred
    

    Note: Same error occurred when I tried to do the following:

    Invoke-Command -ComputerName localhost -ScriptBlock {Get-Command -Name Add-ClusteriSCSITargetServerRole}
    

    b. Second Set:

    Get-Command -Name Add-* -Module IscsiTarget < --- I know this is the Module the cmdlet is a part of from my testing (See further down).
    
    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Cmdlet          Add-IscsiVirtualDiskTargetMapping                  2.0.0.0    IscsiTarget
    

    Note: Same output occurred when I did the following:

    Invoke-Command -ComputerName localhost -ScriptBlock {Get-Command -Name Add-* -Module IscsiTarget}
    

    c. Third Set:

    Get-Command -Name * -CommandType Cmdlet  -Module IscsiTarget < --- The cmdlet was not in the list.
    

    Note: Same output occurred when I did the following:

    Invoke-Command -ComputerName localhost -ScriptBlock {Get-Command -Name * -CommandType Cmdlet  -Module IscsiTarget}
    

    d. Etc...

    Now, if I used Invoke-Command in combination with wildcards(i.e. * OR Add-*), the cmdlet showed up in the list. So, the following commands listed the command. None of the below Get-Command commands listed the Add-ClusteriSCSITargetServerRole outside Invoke-Command.

    1. First One:

    Invoke-Command -ComputerName localhost -ScriptBlock {Get-Command -Name * -CommandType Cmdlet}
    
    CommandType     Name                               Version    Source        PSComputerName
    -----------     ----                               -------    ------        --------------
    Cmdlet          Add-ClusteriSCSITargetServerRole   2.0.0.0    IscsiTarget   localhost
    

    2. Second One:

    Invoke-Command -ComputerName localhost -ScriptBlock {Get-Command -Name * -CommandType Cmdlet  -Module *}
    
    CommandType     Name                               Version    Source        PSComputerName
    -----------     ----                               -------    ------        --------------
    Cmdlet          Add-ClusteriSCSITargetServerRole   2.0.0.0    IscsiTarget   localhost
    
    

    Hope someone has an idea what's going on. This is driving me nuts.

  • #78731

    Matt Bloomfield
    Participant

    I have no idea what's going on and have spent far too long trying, in vain, to figure this out. I played with the GroupPolicy module and found the 'Block-GPInheritance' cmdlet to be really inconsistent in making an appearance.

    What I have found, that may point you in the right direction, is that for some reason neither of these commands are listed when running

    Get-Module GroupPolicy | Select -ExpandProperty ExportedCommands

    or

    Get-Module iSCSITarget | Select -ExpandProperty ExportedCommands

    but the cmdlets are listed as exported in the module manifests.

  • #78869

    Kevyn
    Participant

    Sorry you spent so much time on this, but I'm glad I'm not the only one seeing something goofy here. Thanks for the help. 🙂

You must be logged in to reply to this topic.