Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell WebAdministration IF Statement with value "False" not working as expected

I’m not sure what I’m missing. This powershell seems to be working the opposite of what I expect. Anyone know why?

$loadUserProfileValue = Get-ItemProperty "IIS:\AppPools\.net v4.5" -Name processModel.loadUserProfile.Value
    Write-Host "Value: $loadUserProfileValue"
    IF ($loadUserProfileValue -eq "False") {
            Write-Host "Since Load User Profile is False, we will now set it to True"}

Here is my Output when Load User Profile is True

Value: True
Since Load User Profile is False, we will now set it to True

Here is my output when Load User Profile is False

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Value: False

The value is being picked up correctly.
The variable $loadUserProfileValue is correct.
The IF Statement is working opposite of what I’m expecting.

I can swap it to be -ne "True" and it seems to work… but why does -eq "False" NOT work?

>Solution :

In PowerShell you use the Boolean data type like this: True = $true and False = $false.

In your case you have to change False to $false

$loadUserProfileValue = Get-ItemProperty "IIS:\AppPools\.net v4.5" -Name processModel.loadUserProfile.Value
Write-Host "Value: $loadUserProfileValue"
IF ($loadUserProfileValue -eq $false) {
        Write-Host "Since Load User Profile is False, we will now set it to True"}

There is already a question on that topic on Stack Overflow: Question

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading