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-

http://blog.itsysintegration.net/powershell-command-line-all-about/

What are variables?

whatisvaribles

  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)
    *User-defined

 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

Vmwarecmdlets

 Constant and Read Only Variables

Constant
*cannot be deleted
*cannot be changed
i.e
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)
i.e
PS C:\> New-varible -Name max -Value 256 -option Readonly

Example: User Defined Variable
Userdefinevariable

 

 

 

 

 

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

Strings

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

powershell1

powercli12

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.

powercli14

 


 

Determine the variable type
determinethevaraibleytpe

 

 

 

Use Variable in a String-

powershellvariableinstring

 

 

 

 

 

 

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 *