簡體   English   中英

System.Management.Automation.PowerShell不會從IIS返回Get-Website的結果

[英]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使用它。 不幸的是,這似乎是一個概念問題。

謝謝您的幫助...

問題是由於在64位系統的“ 構建”選項卡中偏愛32位模式引起的。

首選32位模式

取消選中后,一切正常。

請參閱Powershell Invoke方法,既不引發異常也不返回結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM