下面显示的简单脚本会导致我的计算机出现异常:
Import-Module WebAdministration
Get-ChildItem IIS:\Sites
结果:
powershell -NonInteractive .\test.ps1
Get-ChildItem : Could not load file or assembly 'Microsoft.PowerShell.Commands.Management' or one of its dependencies. The system cannot
find the file specified.
At C:\...\test.ps1:3 char:1
+ Get-ChildItem IIS:\Sites
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetChildItemCommand
但是,如果我在脚本的开头添加 Write-Host 它可以正常工作:
Write-Host '!!!'
Import-Module WebAdministration
Get-ChildItem IIS:\Sites
不幸的是,我不知道是什么导致了这个问题。有人可以帮我吗?