我能够使用 WMI 检索LogFile.Directory
位于远程计算机上的特定 IIS 站点的值。现在我需要更改LogFile.Directory
属性 - 这是自动化过程中的一个步骤 - 但我碰壁了。这是我到目前为止所拥有的,虽然它不起作用。
Write-Output "Making IIS connection to $($XmlCloudNodeFullyQualifiedDomainName)"
$site = Get-WmiObject -ComputerName $XmlCloudNodeFullyQualifiedDomainName -Namespace "root/webadministration" -Class Site -Authentication 6 -Filter "Name = '$IISSiteName'"
If ($site.Name -eq $IISSiteName) {
Write-Output "Found site $IISSiteName"
Write-Output ("Existing log folder: " + $site.LogFile.Directory)
$newLogFolder = "E:\" + $IISSiteName + "\logs"
Write-Output ("Set IIS log folder to " + $newLogFolder)
$site.LogFile.Directory = $newLogFolder
$site.Put()
}
我没有收到任何错误。当我签入 IIS 管理器时,远程计算机上的LogFile.Directory
值不会改变。我读过我应该Set-WMIInstance
改用,所以我尝试了:
Write-Verbose "Making IIS connection to $($XmlCloudNodeFullyQualifiedDomainName)"
$site = Get-WmiObject -ComputerName $XmlCloudNodeFullyQualifiedDomainName -Namespace "root/webadministration" -Class Site -Authentication 6 -Filter "Name = '$IISSiteName'"
$sitePath = (Get-WmiObject -ComputerName $XmlCloudNodeFullyQualifiedDomainName -Namespace "root/webadministration" -Class Site -Authentication 6 -Filter "Name = '$IISSiteName'").__path
If ($site.Name -eq $IISSiteName) {
Write-Output "Found site $IISSiteName"
$newLogFolder = "E:\" + $IISSiteName + "\logs"
Write-Output ("Existing log folder: " + $site.LogFile.Directory)
Set-WmiInstance -Path $sitePath -argument @{LogFile.Directory = $newLogFolder}
Write-Output ("Set IIS log folder to " + $newLogFolder)
}
但这会引发错误:
At E:\\Test.ps1:71 char:54
+ Set-WmiInstance -Path $sitePath @{LogFile.Directory = $newLogFolder}
+ ~
Missing '=' operator after key in hash literal.
At E:\\Test.ps1:72 char:18
+ Write-Output ("Set IIS log folder to " + $newLogFolder)
+ ~
Missing '=' operator after key in hash literal.
At E:\\Test.ps1:41 char:54
+ foreach ($FSMappingNode in $FSMappingNodesArray) {
+ ~
有没有办法远程更改这个特定值或者它是只读属性?任何帮助将不胜感激。谢谢,
//弗朗切斯科