How do you chain multiple sets conditions together when you want either one set or the other set of 2 conditions to be true?
To be more precise, I want to do:
If User is logged in AND Operating system version is Windows 10
OR
User is logged in AND LogonUI process is not running
For example I have:
if (
(Get-WmiObject –ComputerName $poste –Class Win32_ComputerSystem).UserName`
-and`
(Get-WmiObject -Computer $poste -Class Win32_OperatingSystem).Version -like "*10*"
)
{ echo do X }
which is working fine. I want to add the other block of conditions within that same if. I tried this, but it's not working:
if (
(Get-WmiObject –ComputerName $poste –Class Win32_ComputerSystem).UserName`
-and`
(Get-WmiObject -Computer $poste -Class Win32_OperatingSystem).Version -like "*10*"`
-or`
(Get-WmiObject –ComputerName $poste –Class Win32_ComputerSystem).UserName`
-and -not`
(Get-Process -ErrorAction SilentlyContinue -ComputerName $poste -name logonui)
)
{ echo do X }
How do you chain multiple "blocks" like this?
I know I could do two different if statements, but isn't there a way to chain it all together in one statement? The statement contains a lot of code and I don't want to duplicate it.