简体   繁体   English

System.Management.Automation.PowerShell不会从IIS返回Get-Website的结果

[英]System.Management.Automation.PowerShell does not return results for Get-Website from IIS

We're using System.Management.Automation.PowerShell for executing PowerShell scripts. 我们正在使用System.Management.Automation.PowerShell执行PowerShell脚本。

Everything worked fine for many scenarios until we need to set some properties of a web site on IIS (ServerAutostart etc.). 在我们需要在IIS上设置网站的某些属性(ServerAutostart等)之前,一切在许多情况下都可以正常工作。

We made a PS1 script which works as we expected, however, after execution via C#, it crashes. 我们制作了一个PS1脚本,该脚本可以按预期工作,但是通过C#执行后,它崩溃了。 After some exploration, I extracted the problematic part: 经过一番探索,我提取了有问题的部分:

PS1 script: 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"
} 

If I run it via Windows PowerShell ISE , it works perfectly: 如果我通过Windows PowerShell ISE运行它,则可以完美运行:

23 IISSites were found
23 WebSites were found

However, if the script is executed via C# and System.Management.Automation.PowerShell , it returns following: 但是,如果脚本是通过C#和System.Management.Automation.PowerShell执行的,则返回以下内容:

23 IISSites were found
WebSites was not found

What is the difference? 有什么区别? Why Get-IISSite works and Get-Website not? 为什么Get-IISSite可以工作而Get-Website不能工作? Permissions? 权限? Missing modules? 缺少模块?

To set WebSite properties, we need to work with it via Get-WebSite . 要设置WebSite属性,我们需要通过Get-WebSite使用它。 Unfortunately, it seems to be a conceptual problem... 不幸的是,这似乎是一个概念问题。

Thank you for your help... 谢谢您的帮助...

Problem was caused by prefering 32-bit mode in the Build tab in 64-bit system. 问题是由于在64位系统的“ 构建”选项卡中偏爱32位模式引起的。

Prefering 32-bit mode 首选32位模式

After uncheck, everything works well. 取消选中后,一切正常。

see Powershell Invoke method neither throwing exception nor returning result 请参阅Powershell Invoke方法,既不引发异常也不返回结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 .net System.Management.Automation.PowerShell Z8A5DA52ED120547D3A8E70AC 获取完整的 powershell 命令 - Get full powershell command from .net System.Management.Automation.PowerShell api System.Management.Automation.Powershell RunAs管理员 - System.Management.Automation.Powershell RunAs Admin 如何向 powershell 脚本 (System.Management.Automation.Powershell) 提供参数? - How to supply parameters to powershell script (System.Management.Automation.Powershell)? 在PowerShell上运行良好的脚本使用System.Management.Automation.PowerShell返回错误 - Script that runs fine on PowerShell returns error using System.Management.Automation.PowerShell C#调用powershell“Get-Website”总是返回空 - C# Invoke powershell "Get-Website" always return empty C#System.Management.Automation.Powershell类在Invoke()调用时泄漏内存 - C# System.Management.Automation.Powershell class leaking memory on Invoke() call 性能:System.Diagnostics.Process与System.Management.Automation.PowerShell - Performance: System.Diagnostics.Process vs System.Management.Automation.PowerShell 如何使System.Management.Automation.PowerShell输出与run thru命令行相同 - How to make System.Management.Automation.PowerShell output same as run thru command line System.Management.Automation中没有PowerShell? - No PowerShell in System.Management.Automation? 为什么从C#调用PowerShell会抛出System.Management.Automation.CommandNotFoundException? - Why does invoking PowerShell from C# throw a System.Management.Automation.CommandNotFoundException?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM