Windows Powershell-Introduction

Powershell-Intro Section

This section is posting to help with an introduction to Powershell. If you need know get more in-dept input on the Powershell Extension, Module, Cmdlets, and PowerCLI related topic.


Go to the section MS Power shell and and Vmware PowerCLI-

What are variables?


  1. Unit of memory
  2. Begin with dollar sign(4)
  3. Variable names can include spaces and special characters. 
  4. Note case-sensitive:
    *Automatic (built-in)

 i. Automatic Variables
a. Built-in
    b. Created and maintenance. by Power shell
    c. Store Power shell State. 

For example:

  • $Error : List of all errors
  • $? : Execution status of last operation
  • $HOME: User’s Home Directory
  • $Host: Object representing current host application for Poswershell
  • $NULL: NULL or empty value
  • $PSHOME: Full path of installation directory for Powershell
  • $True: Represents TRUE in commands
  • $False: Represent FALSE in commands

ii. User-Define Variables

  • Created and maintained by user
  • Existing only in current session
  • Lost when session is closed

iii.Variable CMDLETS


 Constant and Read Only Variables

*cannot be deleted
*cannot be changed
PS:C:\> New-Variable -Name pi -value  3.1419265 -option constant

Read Only:
*Can be deleted (except using -force)
*Cannot be changed (except using -force)
PS C:\> New-varible -Name max -Value 256 -option Readonly

Example: User Defined Variable






Data Type

*Everything is an OBJECT
*Each OBJECT has a TYPE

Example: Literal String

Create a variable
PS C:\  $a =123

Include the variable in a literal string(single-quotes)
PS C:\ $b =’As easy as $a’

Notice that $a is not expanded

PS C:\> $b
As easy as $a


*Simplify use of longer; more complex string assignments
*Here String can contain quotes, @ sign, etc



Variable Sub -Expression
*Returns the result of one or more enclosed statements
*Can be used to access an object property and concatenate its value within an expandable string.




Determine the variable type




Use Variable in a String-








Use a Variable in Data Types

What is Data Type in Powershell?

Data Type supports many other data types, such as floating point numbers, strings, and Boolean values. You don’t have to explicitly declare the data type of a variable; PowerShell automatically chooses the data type for you when you initialize the variable—that is, when you first assign a value.

  • Everything is an Object
  • Each Object has a TYPE

Example Expandable Strings

Create a varaible
PS C:\>  $a =123
Include the variable in a literal string (single -quotes)
PS C:\> $b =‘As easy as $a’
Notice that $a is not expanded
PS c:\c $b
As easy as $a

Example of Here Strings



Leave a Reply

Your email address will not be published. Required fields are marked *