powershell - 对使用 New-Item cmdlet 创建的项目进行 Psedit 会引发异常

标签 powershell powershell-ise

当我使用 New-Item cmdlet 创建新文件并希望使用 psedit 在 PowerShell ISE 中编辑它时,我收到以下异常:

Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an object."
At line:7 char:13
+             $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $nul ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

代码:

New-Item readme.txt
psedit readme.txt

Ps版本表:

Name                           Value                                                                                                                                                     
----                           -----                                                                                                                                                     
PSVersion                      5.0.10586.494                                                                                                                                             
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                   
BuildVersion                   10.0.10586.494                                                                                                                                            
CLRVersion                     4.0.30319.42000                                                                                                                                           
WSManStackVersion              3.0                                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                                       
SerializationVersion           1.1.0.1       

这是一个已知的错误吗?有什么解决办法吗?

最佳答案

运行以下命令不会出现问题,并在 ISE 中使用 readme.txt 打开一个新选项卡:

New-Item Readme.txt -ItemType file
psedit Readme.txt

PS版本表:

    Name                           Value                                                                                                                                                                                                                            
----                           -----                                                                                                                                                                                                                            
PSVersion                      4.0                                                                                                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                                                                                              
SerializationVersion           1.1.0.1                                                                                                                                                                                                                          
CLRVersion                     4.0.30319.34209                                                                                                                                                                                                                  
BuildVersion                   6.3.9600.17400                                                                                                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                                                                                                                                                                                                             
PSRemotingProtocolVersion      2.2    

关于powershell - 对使用 New-Item cmdlet 创建的项目进行 Psedit 会引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38968672/

相关文章:

Powershell move 最近的文件

powershell - 获取Invoke-Command的状态

.net-4.0 - 使用CurrentDomain.SetData ("APP_CONFIG_FILE")在PowerShell ISE中不起作用

powershell - 如何在powershell中测量窗口高度(行数)?

powershell - 测试路径无法在存在的文件上返回 $True

linux - 如何将剪切命令与文本限定符一起使用

powershell - 有没有办法定义一个无参数的powershell参数集?

正则表达式和 Powershell : Use Regex to Create Files based on name found in CSV

powershell - 如何在PowerShell中将文件复制到多个文件夹

powershell - 在 Powershell 中工作时,如何在列表项之间暂停?