0

请有人可以看看这个并告诉我我做错了什么?我正在尝试使用 powershell 和 wmi 修改 IIS 网站中的自定义错误消息属性...这就是我想出的。

    $Server = "localhost" 
    $Wmi = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" -ComputerName $server -filter "ServerComment = 'SharePoint - SP80'" -Authentication 6
    $CustomHttpError = $wmi | Foreach-Object { $_.HttpErrors | ? {$_.HttpErrorCode -contains "400"} | Select HttpErrorCode, HttpErrorSubcode, HandlerType,HandlerLocation;}
    $CustomHttpError.HandlerLocation('C:\WINDOWS\help\iisHelp\common\Custom.htm')

我收到错误消息“方法调用失败,因为 [Selected.System.Management.ManagementBaseObject] 不包含名为 'HandlerLocation' 的方法”

当我使用 Get-Member 检查 $CustomHttpError 时,我得到以下信息。

类型名称:Selected.System.Management.ManagementBaseObject

Name MemberType 定义
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString方法字符串 ToS​​tring()
HandlerLocation NoteProperty System.String HandlerLocation=C:\WINDOWS\help\iisHelp\common\400.htm HandlerType NoteProperty System.String HandlerType=FILE
HttpErrorCode NoteProperty System.String HttpErrorCode=400
HttpErrorSubcode NoteProperty System.String HttpErrorSubcode=*

如果 HandlerLocation 属性不是我可以调用的方法,我该如何修改它?

4

1 回答 1

0

尝试:

$Server = "localhost" 
$Wmi = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" -ComputerName $server -filter "ServerComment = 'SharePoint - SP80'" -Authentication 6

#Get httperrors array
$HttpErrors = $wmi.HttpErrors
#Changing 400 error pages
$HttpErrors | % { if ($_.HttpErrorCode -eq "400") { $_.HandlerLocation = "C:\WINDOWS\help\iisHelp\common\Custom.htm" } }

#Set updated httpserros property
$wmi.HttpErrors = $HttpErrors
#Save object
$wmi.Put()
于 2013-01-18T12:48:09.887 回答