Peer review: function - Set-IISProcessModelLoadUserProfileBool

Discussion Peer review: function - Set-IISProcessModelLoadUserProfileBool

  • Wednesday, May 23, 2012 5:33 PM
     
      Has Code

    This function is relatively simple. It just took me a little while to find the right syntax for the property I needed to tweak.  In short, it updates the LoadUserProfile value for AppPool process model on IIS. I made it so it would take true (1) or false (0). In my example I flip back and forth a few times.  Let me know if I missed anything and how I can improve upon it. 

    clear-host
    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."
    		}
    	}
    }
    
    Set-IISProcessModelLoadUserProfileBool 1
    Set-IISProcessModelLoadUserProfileBool 0
    Set-IISProcessModelLoadUserProfileBool 0
    Set-IISProcessModelLoadUserProfileBool 1

All Replies

  • Wednesday, May 23, 2012 5:37 PM
     
     
    I'd lose the terminating semicolons.
      - Larry
     
     
  • Wednesday, May 23, 2012 5:43 PM
     
     

    Never;

    Sorry, couldn't resist. I know, I know: "Semicolons are bad." I just can't get past my C# days.