0

I'm trying to create a script to audit the IIS recycling times on a number of remote servers. The script I'm attempting is:

$scriptBlock = {
import-module webadministration
Get-itemproperty -Path IIS:\AppPools\WebPage -Name recycling.periodicRestart.schedule.collection}
invoke-command -computername HOSTNAME -ScriptBlock $scriptBlock

Unfortunately, this is returning absolutely nothing. Any idea what I might be doing wrong?

Christopher Cass
  • 817
  • 4
  • 19
  • 31

1 Answers1

0

You are not doing anything wrong, assuming you want to query the "DefaultAppPool," what you are doing will return empty if there is no value in the collection:

Get-ItemProperty -Path IIS:\AppPools\DefaultAppPool -Name recycling.periodicRestart.schedule.collection

Set it with:

Set-ItemProperty -Path IIS:\AppPools\DefaultAppPool -Name recycling.periodicRestart.schedule -Value @{value = '03:00:00'}

And then try to get it, you will see the value.

Ben Richards
  • 3,437
  • 1
  • 14
  • 18
  • No, I'm not going for the default. I'm going for one called "webpage" and I can verify that it's set to 2AM... But for some reason this returns no results when I try to pull it from a different location. if I run import-module webadministration $iisrecycling = Get-itemproperty -Path IIS:\AppPools\WebPage - Name recycling.periodicRestart.schedule.collection $IISTime = $iisrecycling.value.hours I get results locally, but not when trying to do it remotely. – Christopher Cass May 24 '17 at 15:50
  • The "DefaultAppPool" was just an example I was using to show you how to get it and set it. What do you mean by "remotely?" Through Posh remote session or on a different server? – Ben Richards May 24 '17 at 17:26
  • I want to get it from a different server. My goal is to audit about 50 servers with one query, but I can't get it to return the result from a single server, unless I'm signed directly into that server. – Christopher Cass May 25 '17 at 14:25
  • Ah, I see, let me check into that. – Ben Richards May 25 '17 at 14:26