0
我能夠使用WMI檢索位於遠程計算機上的特定IIS站點的值LogFile.Directory
。 現在我需要更改LogFile.Directory
屬性 - 這是自動化過程中的一個步驟 - 但是我打了一堵牆。這是我迄今爲止,雖然它不起作用。如何在遠程計算機上通過WMI更改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) {
+ ~
有沒有辦法遠程更改這個特定的值或者是一個只讀屬性? 任何幫助將不勝感激。 謝謝,
//弗朗西斯