[英]Get full powershell command from .net System.Management.Automation.PowerShell api
[英]System.Management.Automation.PowerShell does not return results for Get-Website from IIS
我们正在使用System.Management.Automation.PowerShell
执行PowerShell脚本。
在我们需要在IIS上设置网站的某些属性(ServerAutostart等)之前,一切在许多情况下都可以正常工作。
我们制作了一个PS1脚本,该脚本可以按预期工作,但是通过C#执行后,它崩溃了。 经过一番探索,我提取了有问题的部分:
PS1脚本:
# Set execution policy
Set-ExecutionPolicy Unrestricted -Scope Process -Force
Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
# Import modules
Import-Module WebAdministration
Import-Module IISAdministration -MinimumVersion 1.1.0.0
# Getting IIS Sites
$iisSite = Get-IISSite
If ($iisSite)
{
Write-Host "$($iisSite.Count) IISSites were found"
}
else
{
Write-Error "IISSite was not found"
}
$webSite = Get-Website
# Getting Web Sites
If ($webSite)
{
Write-Host "$($webSite.Count) WebSites were found"
}
else
{
Write-Error "WebSites was not found"
}
如果我通过Windows PowerShell ISE
运行它,则可以完美运行:
23 IISSites were found
23 WebSites were found
但是,如果脚本是通过C#和System.Management.Automation.PowerShell
执行的,则返回以下内容:
23 IISSites were found
WebSites was not found
有什么区别? 为什么Get-IISSite
可以工作而Get-Website
不能工作? 权限? 缺少模块?
要设置WebSite属性,我们需要通过Get-WebSite
使用它。 不幸的是,这似乎是一个概念问题。
谢谢您的帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.