PowerShell - Having trouble setting Specific Recycle Time in IIS App Pool - powershell

When it comes to IIS App Pool Recycling, under the Recycling settings, you can set a Specific Time to Recycle. You can also set multiple times by doing 00:15, 04:30. See following screenshot.
I am attempting to set multiple Recycle Times using PowerShell. The odd thing is, when I run my code - it only shows 00:15 in the GUI - not 00:15 and 04:30.
But - if I run this check, it shows both times set.
Get-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name Recycling.periodicRestart.schedule.collection
Now, if I go into the GUI and add a time that way - it shows, but it wipes out 04:30.
I am wanting to know why when I set multiple times in PS - they do not all show in the GUI. Other people can run my code and see both times in the GUI. Any thoughts?
Thanks.
Import-Module WebAdministration
$RecycleTime1 = '00:15'
$RecycleTime2 = '04:30'
$PrivateMemory = 1468006
$sites = Get-ChildItem 'IIS:\AppPools\' <# | Where-Object { $_.recycling.periodicRestart.schedule.TotalMilliseconds -gt 1 } #>
Clear-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name Recycling.periodicRestart.schedule
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" Recycling.periodicRestart.schedule -Value #{value=$RecycleTime1}
New-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name Recycling.periodicRestart.schedule -Value #{value=$RecycleTime2}
Get-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name Recycling.periodicRestart.schedule.collection
EDIT:
Looks like value may need an index. Trying to figure out if so.
AppCmd set config
-section:system.applicationHost/applicationPools
"/+applicationPoolDefaults.recycling.periodicRestart.schedule.[#0,value='04:00:00']"
/commit:apphost

Related

Pause windows update for up to 35 days and find out until which date updates are paused, via powershell

In Windows 10 it is possible to pause windows updates for up to 35 days using the "Windows Update - Advanced Options" settings dialog (please see screenshot).
Question 1:
How do i accomplish that via powershell or command-line ?
Question 2:
How do i find out until which date windows updates are paused via powershell or commandline? Or alternatively: How do i find out how many days are left until windows updates are resumed ?
Here is an easy way to do it in Powershell by amending the Registry:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseUpdatesExpiryTime' -Value "2020-07-31T00:00:00Z"
Finally to query the current setting:
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings'| Select-Object PauseUpdatesExpiryTime
This has been tested, the only side-effect is that the date setting dropdown is greyed out in the Advanced setting page.
one-liner that does it, based on Ozymanduis's comment:
$pause = (Get-Date).AddDays(35); $pause = $pause.ToUniversalTime().ToString( "yyyy-MM-ddTHH:mm:ssZ" ); Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseUpdatesExpiryTime' -Value $pause
Thanks Ozymanduis for the suggestion. I tried it and it worked fine.
Probably windows 10 needs the exact time format to accept the pause updates function and to work properly. However I went looking into the registery where those keys are, after pressing the pause updates function. It seems that there are other REG keys which are created during the "button press". And those are
PauseFeatureUpdatesStartTime (Where the time format is set on "now")
PauseFeatureUpdatesEndTime (Where the time format is set on "in 35 days")
PauseQualityUpdatesStartTime (Where the time format is set on "now")
PauseQualityUpdatesEndTime (Where the time format is set on "in 35 days")
So I just added those keys to the equation like this
$pause = (Get-Date).AddDays(35)
$pause = $pause.ToUniversalTime().ToString( "yyyy-MM-ddTHH:mm:ssZ" )
$pause_start = (Get-Date)
$pause_start = $pause_start.ToUniversalTime().ToString( "yyyy-MM-ddTHH:mm:ssZ" )
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseUpdatesExpiryTime' -Value $pause
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseFeatureUpdatesStartTime' -Value $pause_start
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseFeatureUpdatesEndTime' -Value $pause
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseQualityUpdatesStartTime' -Value $pause_start
Set-itemproperty -Path 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -Name 'PauseQualityUpdatesEndTime' -Value $pause
Now I hope it will really pause those updates. I remember having tried out the "pause" REG keys function couple of years ago alternatively to the "disable windows updates" function, but somehow it used to resume those updates within the grace period regardless of the date set, which was kind of annoying. I will keep you updated.
EDIT: I added the reg entries in the same ps file to avoid the autoupdate feature to start like this,
New-Item -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' -Force
New-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' -Name 'NoAutoUpdate' -PropertyType DWORD -Value 1
I do it as soon as possible when our machines are deployed to avoid the update process to begin (because if it does you're pretty much screwed) and it seems to work pretty fine now:

Updating registry remotely in powershell not saving after reboot

I am doing an automated deployment process within a single server that deploys a few different virtual machines. Once all the virtual machines are imported using a base image I start them and rename them and try to setup the auto logon process by setting the expected registry keys.
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "AutoLogonCount" -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "DefaultUserName" -Value "$Username" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "DefaultPassword" -Value "$Password" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "AutoAdminLogon" -Value "1" -Force
This is wrapped in an Invoke-Command with a working session and passing in the correct information into it. After this has been ran I use [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( method to obtain the key value information and verify it has been set correctly. Which everything equals what it should.
However once this is complete I do a reboot of the virtual machine but occasionally a vm will not have the registry keys saved and it will not login automatically. When I manually login and look at the registry the keys are blank or not created.
I even have it written up that after the reboot if the registry keys do not equal what they should to try again, and after every attempted reboot to login automatically the keys seemingly disappear. I am running it again as I am writing this to attempt to do it and this time look in the event logs to see if anything is found.
This process can take some time since it doesn't seem to happen consistently and I delete the vms and run the automated process from scratch.

How to setup IIS App Pool Cpu rate limit using powershell

I am trying to set cpu rate limit i was able to perform this action in UI using the action link
https://theitbros.com/set-cpu-usage-limit-for-an-application-pool-iis-8/
but i want to set three values below using powershell
CPU limit=20%
CPU limit Action= Killw3p
Cpu Limit Interval= 1
Iam already using powershell to setup startmode to always running.
set-itemproperty IIS:\AppPools\AddressBroker.API -name startMode -value AlwaysRunning
I have tried something like below but does not work.
set-itemproperty IIS:\AppPools\AddressBroker.API -name CPU -value Limit=20%
If you're looking for the PowerShell solution, you'll need to correct the property name:
Import-Module WebAdministration
$appPool = Get-Item IIS:\AppPools\AddressBroker.API
$appPool | Set-ItemProperty -name "cpu.limit" -value 20000
$appPool | Set-ItemProperty -name "cpu.action" -value "ThrottleUnderLoad"
$appPool | Set-ItemProperty -name "startMode" -value "AlwaysRunning"
I figured out the correct command that works for me is below.
C:\windows\system32\inetsrv\appcmd.exe set apppool AppPOOLName /cpu.limit:20000 /cpu.action:KillW3wp /cpu.resetInterval:00:01:00
According to your description, I suggest you could try to use below command to acheive your requirement.
C:\windows\system32\inetsrv\appcmd.exe set apppool /cpu.limit:20000 /cpu.action:KillW3wp /cpu.resetInterval:00:01:00
Result:

Use powershell to configure "Use start fullscreen" setting?

Windows 10 allows you to configure Settings > Start > Use Start full screen, I'm trying to find a way to configure this through powershell/dsc scripting/automation. I was able to find the MDM and GPO documentation (https://learn.microsoft.com/en-us/windows/configuration/windows-10-start-layout-options-and-policies) but this does not appear to apply to desktop Windows 10 Pro - powershell has no commands/cmdlets with GP* nouns.
The scripts below, inspired by the .bat-files in this article adjust the local policies and should probably work. I have tested on 10.0.16299.431 (Enterprise).
Based on the article (Created by Shawn Brink, January 24th 2015):
To force fullscreen:
$forceStartSizePath = "\Software\Policies\Microsoft\Windows\Explorer"
New-ItemProperty -Path "HKCU:$forceStartSizePath" -Name "ForceStartSize" -Value 2 -Force
New-ItemProperty -Path "HKLM:$forceStartSizePath" -Name "ForceStartSize" -Value 2 -Force
Stop-Process -name explorer
To force normal mode:
$forceStartSizePath = "\Software\Policies\Microsoft\Windows\Explorer"
New-ItemProperty -Path "HKCU:$forceStartSizePath" -Name "ForceStartSize" -Value 1 -Force
New-ItemProperty -Path "HKLM:$forceStartSizePath" -Name "ForceStartSize" -Value 1 -Force
Stop-Process -name explorer
To reset to default:
$forceStartSizePath = "\Software\Policies\Microsoft\Windows\Explorer"
Remove-ItemProperty -Path "HKCU:$forceStartSizePath" -Name "ForceStartSize"
Remove-ItemProperty -Path "HKLM:$forceStartSizePath" -Name "ForceStartSize"
Stop-Process -name explorer
Note: The last line (making explorer restart) may not desirable, but it will make sure the settings are picked up instantly. Your screen will flicker (if running local) as explorer is restarted.
Also; if parts of the registry-path is missing, you will get an error message. Use Test-Pathand New-Item to check for and create the missing part of the path.

Get Specific Recycling Time For IIS With PowerShell

I'm trying to find the specific time that my app pool is set to recycle on my server using PowerShell. I know it's set to recycle at 1 AM daily on the test server that I'm looking at. I'm running:
Get-ItemProperty -Path IIS:\AppPools\AppPool -Name recycling.periodicRestart.time
and the value that's showing is 00:00:00
For testing purposes, I attempted to run:
Set-ItemProperty -Path IIS:\AppPools\AppPool -Name recycling.periodicRestart.time -Value 3.00:00:00
I checked to see how this changed. The "Specific Time(s)" field still reads 1:00 AM, but now the "Regular Time Intervals (in minutes)" is set to 4320 minutes. So apparently I'm looking at the wrong value... Any idea how I can see the value in the "Specific Time" field?
Here you go:
Set-ItemProperty -Path IIS:\AppPools\DefaultAppPool -Name recycling.periodicRestart.schedule -Value #{value = '03:00:00'}
Get it with:
Get-ItemProperty -Path IIS:\AppPools\DefaultAppPool -Name recycling.periodicRestart.schedule.collection