Description
Steps to reproduce
Open any powershell script
Press Alt+Shift+F or right click and select 'Format Document'
Expected behavior
Format document
Actual behavior
Powershell Extension crashes
Turned on verbose logging and this is what it outputs:
8/16/2018 2:07:32 PM [VERBOSE] - Formatting entire document - file://(FILEPATH)/RemoveAllNetworkPrintersv2.ps1...
8/16/2018 2:07:32 PM [VERBOSE] - Document formatting failed in 0.064: Error: Connection got disposed.
8/16/2018 2:07:35 PM [NORMAL] - powershell.exe terminated or terminal UI was closed
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
(Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
I can't seem to get this command to work???
Windows 7.
Additional Notes
Running Invoke-Formatter command brings up another error:
Invoke-Formatter : The term 'Invoke-Formatter' 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 \\servername\path\test2.ps1:2 char:1
+ Invoke-Formatter -ScriptDefinition (get-Content $scriptPath) -Verbose
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Invoke-Formatter:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I think the issue is the PSScriptAnalyzer module is not installed correctly. So I have tried to manually import it. Using command 'Import-Module .\PSScriptAnalyzer.psm1'
I then try to run the Invoke-Formatter command again and get this issue:
Invoke-Formatter : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ScriptDefinition'. Specified method is not supported.
At \\server\path\test2.ps1:2 char:36
+ Invoke-Formatter -ScriptDefinition (get-Content $scriptPath) -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Formatter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
Interestingly when I run the Get-Module command after I do the manual import it lists PSSCriptAnalyzer as installed but the version number 0.0
> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 0.2.0 PowerShellEditorServices.Commands {ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast, Get-Token...}
Script 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlContentView, Set-VSCodeHtmlContentView, Show-VSCodeHtmlContentView...}
Script 0.0 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}
Please let me know if I need to provide anything further