【发布时间】:2024-05-14 21:40:03
【问题描述】:
我能够使用 WMI 检索位于远程计算机上的特定 IIS 站点的 LogFile.Directory 值。
现在我需要更改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) {
+ ~
有没有办法远程更改这个特定值,或者它是只读属性? 任何帮助将不胜感激。 谢谢,
//弗朗切斯科
【问题讨论】:
标签: iis-7 wmi get-wmiobject