PowerShell:命令 "Get-ChildItem IIS:\Sites"导致错误

标签 powershell powershell-3.0 web-administration

下面显示的简单脚本导致我的计算机出现异常:

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/

相关文章:

windows - 在计划任务中将参数传递给powershell脚本

powershell - 如何使用 azure CLI 和 power shell 脚本实现自动登录,无需用户交互从 VSTS 进入 azure 门户

powershell-3.0 - 如何在 Powershell 中正确使用 FolderBrowserDialog

powershell - 列出重定向目标 (URL) IIS 站点

powershell - IIS管理和Web管理有什么区别

iis - 如何从 PowerShell 指定应用程序池身份用户和密码

.net - 是否有任何关于 VS 中的 Powershell 编程的文档?

powershell - 请求帮助来解析字符串

powershell - 如何使用Powershell执行命令并获得结果

powershell - 使用Powershell 3下载磁链接