Scripting
PowerShell – Multiple (-and) (-or) within a single If statement
I had a hard time finding examples on the web on how or if you could code multiple If’s into a single If statement, so I thought I would just quick post up an example once I figured out how to do it. Perhaps I wasn’t looking in the right places but all the examples I saw were just a single (-and) or (-or) in the code.
So based on being able to code an If statement in either of the following fashions:
If ($someAttribute -eq $false -or $someAttribute -eq $Null){
}
or the following:
If (($someAttribute -eq $false) -or ($someAttribute -eq $Null)){
}
Then we should be able to do a combined effort:
If (($someAttribute -eq $false -or $someAttribute -eq $Null) -and ($someUser -eq “UserID123″)){
Write-Host “Switching to True”
Set-QADUser $someUser -Service “MyDomain.org” -ObjectAttributes @{$someAttribute = $True}
If (!$?) {Write-Host “Error: $($error[0])”}
}
So if $someAttribute is either $false or $Null AND #someUser equals “UserID123″ then do something… in this case I switch the Attribute someAttribute to $true and do some error checking.
~ITNotes
PowerShell 2.0 Release Candidate for Windows Vista and Server 2008
Still waiting for PowerShell 2.0 for Windows XP and Server 2003, but this is a good start.
Read more from the source: http://blogs.msdn.com/powershell/archive/2009/08/14/powershell-2-0-for-windows-vista-and-windows-server-2008-release-candidate.aspx
Download here: https://connect.microsoft.com/windowsmanagement/Downloads
