Powershell Reset

Hello All, I have run into an issue with Powershell updating what is recognizes as system settings.

So I have built out a script which performs the following actions:

  1. Install IIS and Features - Working
  2. Remove default website and apppool - Working
  3. Restore IIS settings using Restore-WebConfiguration - Working
  4. Change IIS AppPool Identities - NOT Working
It seems that running Get-IISAppPool within the same PowerShell instance you just installed from will not identify any AppPools. I ensured I had the WebAdministration module imported and that the AppPools show within IIS Management GUI however PowerShell will not see them. Now if I close that instance of PowerShell and run the exact same commands they display.

My question: Is there a way to sort of reset PowerShell to get it to see changes such as this within the same script or have I perhaps made a mistake?

Work Around: I suppose I could execute the script with parameters. Step 1 would be to install everything and once completed execute another instance of the script with a parameter to begin Step 2 which would configure the rest. This just seems like it would not be the proper method.

Any advice? Thanks

I used a combination of the WebAdministration and IISAdministration modules. I assume you are too since you listed a cmdlet from each one.
I went through the steps I think you tried and it worked for me. Below is what I tried:

Backup-WebConfiguration -Name 'webConfig'
Remove-Website -Name 'Default Web Site'
Remove-WebAppPool -Name 'DefaultAppPool'
Reset-IISServerManager #run this then confirm the application pool and website are gone
Restore-WebConfiguration -Name 'webConfig'
Reset-IISServerManager
Get-IISAppPool

The only way I could get the application pools to not display after deletion was to reset the server manager first.