PowerShell built in variables

Hello everybody,

today I want to write few words about PowerShell variables.

So, let's start from the simplest or with statement what is true and what is false. 

In PS it's really not philosophical question

$false

$true

The first one stands for false, and the second one for true. It is intended for logical operations in PS.

Very usefull is Users Home directory:

$Home

Current directory:

$pwd

Information about users environment:

$host

If you ever need to discover which version of power shell, that you execute, you can use 

$PSVersionTable

Let's say that you write some kind of loop, and wonder where current item goes in, you have relieve, for this purpose you can use 

$_

As an example consider following code, which will set location to folder temp, and with help of $_ will filter files, which have in extension letter t:

Set-Location C:\Temp

Get-ChildItem | Where-Object {$_.Name -like "*.*t*" }

Or little bit another way:

Set-Location C:\Temp

dir | Where-Object {$_.Name -like "*.*t*" }

No Comments

Add a Comment