Reputation: 25
The following code is used to output a table that shows what items are requiring the PC to need a restart. It basically compiles each type/reason for a restart and outputs the results.
My question is how is the line for New-Object
setting the RebootPending
object when there are multiple variables listed?
Questionable Line:
RebootPending=($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)
Full snippet:
## Creating Custom PSObject and Select-Object Splat
$SelectSplat = @{
Property=(
'Computer',
'CBServicing',
'WindowsUpdate',
'CCMClientSDK',
'PendComputerRename',
'PendFileRename',
'PendFileRenVal',
'RebootPending'
)}
New-Object -TypeName PSObject -Property @{
Computer=$WMI_OS.CSName
CBServicing=$CBSRebootPend
WindowsUpdate=$WUAURebootReq
CCMClientSDK=$SCCM
PendComputerRename=$CompPendRen
PendFileRename=$PendFileRename
PendFileRenVal=$RegValuePFRO
RebootPending=($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)
} | Select-Object @SelectSplat
Bonus:
How do I use the RebootPending
in an if
/else
to set the PowerShell error code to 1 if it is "True?"
Upvotes: 1
Views: 206
Reputation: 5862
RebootPending=($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)
That is setting the bool
property by conditionally OR
ing other variables.
Take a look at this example, showing how this conditional behavior works:
$Option1 = $true
$Option2 = $true
$Option3 = $true
$Result = $option1 -or $Option2 -or $Option3
$Result
# True
$Option1 = $false
$Option2 = $true
$Option3 = $false
$Result = $option1 -or $Option2 -or $Option3
$Result
# True
$Option1 = $false
$Option2 = $false
$Option3 = $false
$Result = $option1 -or $Option2 -or $Option3
$Result
# False
Upvotes: 2