platyPS icon indicating copy to clipboard operation
platyPS copied to clipboard

New-MarkdownHelp 0.14.1 generates bogus errors when using the Session parameter.

Open chrisda opened this issue 3 years ago • 7 comments

The newer 0.14.1 version of platyPS does something that the 0.14.0 version does not:

If you use the Session parameter with New-MarkdownHelp (which I'm forced to do with Exchange, since all Exchange PowerShell is remote), the same error is repeated in proportion to the number of parameters in the cmdlet (which is a big deal if you also use the Module parameter; it's a sea of red errors interspersed with successful cmdlet names).

You cannot call a method on a null-valued expression.
At C:\Users\jdoe\Documents\WindowsPowerShell\Modules\platyPS\platyPS.psm1:2678 char:25
+                     if ($Attribute.TypeId.ToString() -eq 'System.Management.Auto ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I've verified the following aspects:

  • These errors DO NOT occur in 0.14.1 if you omit the Session parameter (again, not a viable option for me, but I confirmed it).
  • These errors DO NOT affect the output of New-MarkdownHelp. I dumped the same cmdlet to a markdown file using the 0.14.0 and 0.14.1 versions of platyPS, and then used WinMerge to confirm that the two markdown files are identical.

Attached are the two markdown files for analysis. Output.zip

Steps to reproduce

  1. Connect to Exchange Online PowerShell.

  2. Run the following commands:

    $Session = Get-PSSession
    New-MarkdownHelp -Session $Session -Command Get-HostedConnectionFilterPolicy -OutputFolder C:\z_MAML_Generation
    

Expected behavior

The command should run error free as it does in 0.14.0:

PS C:\Users\jdoe> New-MarkdownHelp -Session $Session -Command Get-HostedConnectionFilterPolicy -OutputFolder C:\z_MAML_Generation

    Directory: C:\z_MAML_Generation

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2/26/2021  11:00 AM           3081 Get-HostedConnectionFilterPolicy.md

Actual behavior

The command successfully generates the correct markdown topic, but the the console output contains bogus errors:

PS C:\Users\jdoe> New-MarkdownHelp -Session $Session -Command Get-HostedConnectionFilterPolicy -OutputFolder C:\z_MAML_Generation
You cannot call a method on a null-valued expression.
At C:\Users\jdoe\Documents\WindowsPowerShell\Modules\platyPS\0.14.1\platyPS.psm1:2678 char:25
+ ...         if ($Attribute.TypeId.ToString() -eq 'System.Management.Autom ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\jdoe\Documents\WindowsPowerShell\Modules\platyPS\0.14.1\platyPS.psm1:2678 char:25
+ ...         if ($Attribute.TypeId.ToString() -eq 'System.Management.Autom ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Directory: C:\z_MAML_Generation

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2/26/2021  11:04 AM           3081 Get-HostedConnectionFilterPolicy.md

Environment data

  • platyPS: 0.14.1
  • Windows 10 Enterprise 20H2, Windows Server 2012 R2 Datacenter, Windows Server 2016 Datacenter
  • Windows PowerShell 5.1

chrisda avatar Feb 26 '21 19:02 chrisda

@chrisda Are you saying that error does not happen with 0.14.0?

sdwheeler avatar Jul 26 '21 16:07 sdwheeler

@sdwheeler, correct. No errors with 0.14.0.

chrisda avatar Jul 26 '21 17:07 chrisda

@chrisda Can you test with https://github.com/PowerShell/platyPS/releases/tag/v2.0.0-preview1?

sdwheeler avatar Jul 26 '21 17:07 sdwheeler

@adityapatwardhan Can you take a look at this error message and see if something creeped in. I didn't think we made changes here with 14.1 or 14.2.

theJasonHelmick avatar Jul 26 '21 17:07 theJasonHelmick

@sdwheeler, @theJasonHelmick, I tried again with v2.0.0-Preview1 installed from the PowerShell Gallery. Same annoying errors but no effect on the resulting markdown file.

PS C:\WINDOWS\system32> $Session = Get-PSSession
PS C:\WINDOWS\system32> New-MarkdownHelp -Session $Session -Command Get-HostedConnectionFilterPolicy -OutputFolder C:\yyyyyy
You cannot call a method on a null-valued expression.
At C:\Users\jdoe\OneDrive - Microsoft\Documents\WindowsPowerShell\Modules\platyPS\0.14.2\platyPS.psm1:2723 char:25
+ ...         if ($Attribute.TypeId.ToString() -eq 'System.Management.Autom ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\jdoe\OneDrive - Microsoft\Documents\WindowsPowerShell\Modules\platyPS\0.14.2\platyPS.psm1:2723 char:25
+ ...         if ($Attribute.TypeId.ToString() -eq 'System.Management.Autom ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Directory: C:\yyyyyy

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         8/26/2021   4:07 PM           3364 Get-HostedConnectionFilterPolicy.md

chrisda avatar Aug 26 '21 23:08 chrisda

@chrisda I think the error you are seeing is being caused by the fact that your documents folder is in OneDrive. Can you exclude it from OneDrive and move it back to your profile?

sdwheeler avatar Aug 30 '21 17:08 sdwheeler

@sdwheeler, I had to try on a different computer with no OneDrive redirection.

0.14.2 gives the same nuisance errors, but works fine just like before.

2.0.0 gives a new error and doesn't work at all:

New-MarkdownHelp : The term 'Get-Command' 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.
At line:1 char:1
+ New-MarkdownHelp -Session $Session -Command Get-HostedConnectionFilte ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Command:String) [New-MarkdownHelp], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Get-Command and Get-HostedConnectionFilterPolicy are available and work just fine (I tested).

chrisda avatar Aug 30 '21 22:08 chrisda