[英]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.