Psedit 对使用 New-Item cmdlet 创建的项目抛出异常
Psedit on a item created with the New-Item cmdlet throws exception
当我使用 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
PsVersionTable:
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
PSVersiontable:
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 V5 错误,因为它在 PowerShell V4 上运行良好(请参阅 )。解决方法是使用 Out-File
cmdlet 创建文件:
'' | Out-File readme.txt
psedit readme.txt
当我使用 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
PsVersionTable:
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
PSVersiontable:
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 V5 错误,因为它在 PowerShell V4 上运行良好(请参阅 Out-File
cmdlet 创建文件:
'' | Out-File readme.txt
psedit readme.txt