cloudbase / windows-imaging-tools

Tools to automate the creation of a Windows image for OpenStack, supporting KVM, Hyper-V, ESXi and more.
Apache License 2.0
670 stars 227 forks source link

Fix Is-WindowsClient condition #335

Closed acudovs closed 4 years ago

acudovs commented 4 years ago

First logon animation is always disabled and Administrator account is always enabled on Windows client versions because of bug in conditions that always return true.

> function Is-WindowsClient { return $true }
> if (Is-WindowsClient) { Write-Host $true } else { Write-Host $false }
True
> if (Is-WindowsClient -and $true) { Write-Host $true } else { Write-Host $false }
True
> if (Is-WindowsClient -and $false) { Write-Host $true } else { Write-Host $false }
True

To compare the return value of a function in a conditional we must put it in parentheses or assign the return value of the function to a variable and use that variable in the conditional. Otherwise we just call Is-WindowsClient with additional parameter $and = $false which is ignored.

Related discussion https://stackoverflow.com/questions/15930038/condition-with-a-function-call-in-powershell

AppVeyorBot commented 4 years ago

:white_check_mark: Build windows-openstack-imaging-tools 1.0.227 completed (commit https://github.com/cloudbase/windows-openstack-imaging-tools/commit/2bda0ddfed by @AlekseyChudov)

ader1990 commented 4 years ago

Thank you for the fix, I have overlooked this PS quirk.