PowerShell 6 Logical Operators

Straight from Microsoft


Describes the operators that connect statements in PowerShell.


The PowerShell logical operators connect expressions and statements, allowing you to use a single expression to test for multiple conditions.

For example, the following statement uses the and operator and the or operator to connect three conditional statements. The statement is true only when the value of $a is greater than the value of $b, and either $a or $b is less than 20.

($a -gt $b) -and (($a -lt 20) -or ($b -lt 20))

PowerShell supports the following logical operators.

-andLogical AND. TRUE when both(1 -eq 1) -and (1 -eq 2)
statements are TRUE.False
-orLogical OR. TRUE when either(1 -eq 1) -or (1 -eq 2)
statement is TRUE.True
-xorLogical EXCLUSIVE OR. TRUE when(1 -eq 1) -xor (2 -eq 2)
only one statement is TRUEFalse
-notLogical not. Negates the statement-not (1 -eq 1)
that follows.False
!Same as -not!(1 -eq 1)


The previous examples also use the equal to comparison operator -eq. For more information, see about_Comparison_Operators. The examples also use the Boolean values of integers. The integer 0 has a value of FALSE. All other integers have a value of TRUE.

The syntax of the logical operators is as follows:Copy

<statement> {-AND | -OR | -XOR} <statement>
{! | -NOT} <statement>

Statements that use the logical operators return Boolean (TRUE or FALSE) values.

The PowerShell logical operators evaluate only the statements required to determine the truth value of the statement. If the left operand in a statement that contains the and operator is FALSE, the right operand is not evaluated. If the left operand in a statement that contains the or statement is TRUE, the right operand is not evaluated. As a result, you can use these statements in the same way that you would use the If statement.

Remote Logoff Windows User

I ran into an issue were my RDP session go corrupted on a test server. I couldn’t logoff. I found this page that tells you how to force a logoff through PowerShell.

# Username to logoff
$userName = 'administrator'
# Get the session id from the server.  In this case the Server ID is 'DC'
$sessionId = ((quser /server:DC | Where-Object { $_ -match $userName }) -split ' +')[2]
# Display the session
# Logoff the Session ID from server DC
logoff $sessionId /server:DC

If you think hard about this you could put this into a script. Just don’t call it ‘logoff.ps1’ since that is a reserved keyword in PowerShell.

Calling a Stored Procedure from OBDC

This topic came up and I found this Oracle documents about using ODBC. Here is an excerpt:

XIV. Calling a Stored Procedure Via ODBC

[See also the Stored Procedures from Microsoft  Visual Basic section of this paper.]

The following is an example of the Visual Basic syntax for calling a stored procedure via ODBC:

db.ExecuteSQL(“{CALL procedurename(param1,param2,param3)}”)

NOTE: This assumes input parameters only and that you have assembled this such that each of the parameters is embedded into the string as a literal. Also note that this syntax DOES NOT work with packaged procedures, for those you must use the alternative begin …end; syntax

In the above example dB is assumed to be a valid database object. If you are using a tool such as MSQuery just use the {CALL …} (ODBC Procedure Call Escape) syntax without the double quotes. You must include the () even when you don’t have any parameters. Out parameters are supported at the ODBC Level 2 conformance (Oracle7 ODBC Version 2.x). The Oracle Level 1 drivers (Version 1.x) will not support this, you must be using a Level 2 or better driver. The 7.3 Oracle driver does not support returning dynasets. This functionality is first implemented in the 8.0.5.x version of the driver. An alternative to the call syntax is shown below:

db.ExecuteSQL(“BEGIN procedurename(param1,param2,param3); END;”, SQLPASSTHROUGH)

This alternative does require the use of the SQLPASSTHROUGH parameter, but will also allow for calling packaged procedures (i.e. packagename.procedurename()).

To return a result set with a stored procedure, refer to the following Microsoft knowledge base articles:

  • Q147938 (RDO)
  • Q126992 (DAO)

The Microsoft provided Oracle ODBC supports this functionality through the use of PL/SQL table types. The Oracle provided drivers do not support this functionality prior to version 8.0.5.x (where it is implemented in PL/SQL by returning a REF CURSOR).

For simple output parameters from a stored procedure you could use the following SQL:

{call procname(?,?)} The above would be passed to SQLExecute() and then have called SQLBindCol() or SQLBindParameter() for the output bind variables (the variables referred to by the ‘?’) you defined in your program. [Note: the Begin; … End; syntax would also work just as well here.] If you are using the Oracle 8.0.x ODBC driver and receiving an ORA-6502 and/or ORA-6512 errors, you must upgrade the driver to version or later and update your MDAC to the latest version.

Have someone else make you password for you

For me I’m always trying to think of a good password without mashing my keyboard. Here are a couple of sites I use:

  • [Strong] Secure Password Generator – Favorite – I put ‘strong’ in brackets because if you search for it Google shows it as ‘Strong Secure Password Generator ‘
  • Norton Password Generate – The antivirus/antimalware company has their own generator. It pretty good and configurable. It’s not my favorite because most of the is cover for advertisement for their other production.
  • LastPass Password Generator – Tons of configuration and really ‘pretty’
  • DashLine – Another pretty with nifty slider. This site was made more for mobile use. So the toll elements may look huge on a conventional monitor.

Find All Columns and Tables in Oracle


Depending on your access you will use one of the following queries:

-- Standard Users
select table_name from all_tab_columns where column_name = 'PICK_COLUMN';
-- DBA Users
select table_name from dba_tab_columns where column_name = 'PICK_COLUMN';
-- Just want to see what table looks like
describe namespace.tableName

If you want some database tool here are ones I like. I usually go for the ‘kitchen sink’ toolsets:

Updated 5/15 – Add looking for column in a known table

FROM all_tab_columns 
WHERE table_name = 'MyTableName'