1

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?"

1 Answer 1

2
RebootPending=($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)

That is setting the bool property by conditionally ORing 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
Sign up to request clarification or add additional context in comments.

1 Comment

Keep in mind that these don't have to be boolean type. Using the comparison operator -or and -and are converting the variables to bool. Strings and number will get evaluated as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.