Skip to content

Instantly share code, notes, and snippets.

@sunnyc7
Created January 28, 2014 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyc7/8671113 to your computer and use it in GitHub Desktop.
Save sunnyc7/8671113 to your computer and use it in GitHub Desktop.
IISLogFileDirectory - interesting behavior
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
}
@sunnyc7
Copy link
Author

sunnyc7 commented Jan 28, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment