Saturday, September 24, 2016

PowerShell v2 Function Set IISProcessModelLoadUserProfileBool

,
In a hurry, so not much time to do anything other than throw this out there. The real challenge for this one was finding the right way to find and set the global value. Using my favorite IIS link I tracked it down. For some reason the indexing starts at 1 instead of 0. Another mystery for another day.
<#
       .NOTES
              Author: Will Steele (wlsteele@gmail.com)
              Last Editted Date: 05/23/2012
             
       .EXAMPLE
              Set-IISProcessModelLoadUserProfileBool 1
      
              This example demonstrates how to set the global LoadUserProfile value to $true.
      
       .EXAMPLE
              Set-IISProcessModelLoadUserProfileBool 0
             
              This example demonstrates how to set the global LoadUserProfile value to $false.
#>

function Set-IISProcessModelLoadUserProfileBool
{
       param(
              [Parameter(
                     Mandatory = $false
              )]
              [Bool]
              $Bool = $true
       )
       $LoadUserProfile = (Get-WebConfigurationProperty -Filter /system.applicationHost/ApplicationPools/ApplicationPoolDefaults[1]/processmodel[1] -Name loaduserprofile -PSPath "Machine/Webroot/apphost").value;
       if($LoadUserProfile -eq $Bool)
       {
              Write-Output "$(Get-Date): LoadUserProfile is already set to $Bool.";
       }
       else
       {
              Write-Output "$(Get-Date): Attempting to set LoadUserProfile to $Bool.";
              Set-WebConfigurationProperty -Filter /system.applicationHost/ApplicationPools/ApplicationPoolDefaults[1]/processmodel[1] -Name loaduserprofile -Value $Bool -PSPath "Machine/Webroot/apphost";
             
              if((Get-WebConfigurationProperty -Filter /system.applicationHost/ApplicationPools/ApplicationPoolDefaults[1]/processmodel[1] -Name loaduserprofile -PSPath "Machine/Webroot/apphost").value -eq $Bool)
              {
                     Write-Output "$(Get-Date): Updated succeeded.";
              }
              else
              {
                     throw "$(Get-Date): Update failed."
              }
       }
}

0 comments to “PowerShell v2 Function Set IISProcessModelLoadUserProfileBool”

Post a Comment

 

Computer Info Copyright © 2016 -- Powered by Blogger