Created
January 28, 2014 16:32
-
-
Save sunnyc7/8671113 to your computer and use it in GitHub Desktop.
IISLogFileDirectory - interesting behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-IISLogFileDirectory { | |
[System.Collections.ArrayList]$x = @() | |
Import-Module "WebAdministration" | |
foreach($site in (dir IIS:\Sites\*)) { | |
$x += [System.Environment]::ExpandEnvironmentVariables((Get-ItemProperty IIS:\Sites\$($site.Name) -name logFile.directory).value) | |
} | |
$x | select -Unique | |
} | |
$sb = (get-command Get-IISLogFileDirectory).Definition | |
#this doesnt work | |
Invoke-Command -ComputerName $server -ScriptBlock $sb | |
#this works | |
Invoke-Command -ComputerName $server -ScriptBlock { | |
[System.Collections.ArrayList]$x = @() | |
Import-Module "WebAdministration" | |
foreach($site in (dir IIS:\Sites\*)) { | |
$x += [System.Environment]::ExpandEnvironmentVariables((Get-ItemProperty IIS:\Sites\$($site.Name) -name logFile.directory).value) | |
} | |
$x | select -Unique | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solution: Courtsey LaerteJunior
https://twitter.com/LaerteSQLDBA/status/428213027432071168
Function Get-IISLogFileDirectory {
[System.Collections.ArrayList]$x = @()
Import-Module "WebAdministration"
foreach($site in (dir IIS:\Sites*)) {
$x += [System.Environment]::ExpandEnvironmentVariables((Get-ItemProperty IIS:\Sites$ ($site.Name) -name logFile.directory).value)
}
$x | select -Unique
}
$sb = [ScriptBlock]::Create((get-command Get-IISLogFileDirectory).Definition)
This works.
Invoke-Command -ScriptBlock $sb -ComputerName $server