下面显示的简单脚本导致我的计算机出现异常:
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
不幸的是,我不知道是什么导致了这个问题。有人可以帮助我吗?
最佳答案
Import-Module WebAdministration
# adding sleep here resolves the issue for me
sleep 2
Get-ChildItem IIS:\Sites
关于PowerShell:命令 "Get-ChildItem IIS:\Sites"导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14862854/