All posts by Thiyagu

Working with PowerShell’s Data Types

An important property of a PowerShell variable is its name, which is always preceded by the dollar sign “$” and can only contain letters, numbers, and the underscore. If you feel a strong urge to use other characters, you have to enclose the name in curly braces. You should not use the name of variables that have been pre-defined.

Windows PowerShell uses the Microsoft .NET Framework data types. The poweshell can supports strings ,integers ,floating point numbers, strings, and Boolean values.You don’t have to explicitly declare the data type of a variable, the PowerShell automatically chooses the data type for you when you initialize the variable—that is,when you first assign a value.

Example: 1 

$GetNumber = Read-Host "Please enter you score" 
$Total = $GetNumber + $GetNumber
Write-Host "The Total Score is $Total"

PowerShell wrongly assumed that the data type of the variable $GetNumber is String. Because the arithmetic operator + is overloaded (the implementation of the operator depends on the arguments), the second line in the program add a string instead of a number.

The second argument of the operator + always has to be a number, so PowerShell automatically converts the data type of $GetNumber into Int32. However, the first argument can also be a string. The result is that PowerShell determines the value of the expression “5”+5, which is 55 ( concatenate the string). 

Example: 2

[INT]$GetNumber = Read-Host "Please enter you score" 
$Total = $GetNumber + $GetNumber
Write-Host "The Total Score is $Total"

In the above code snippet, we explicitly declared the number as Int32 (integer) by enclosing the type name in square brackets before the variable name. So the above variable is called “strongly typed”. If you declare the variable’s data type implicitly in our script the the variable is called as weakly typed.

Data Types:

Data Type NameDescription
[Array]Array
[Bool]Value is TRUE or FALSE
[DateTime]Date and time
[Guid]Globally unique 32-byte identifier
[HashTable]Hash table, collection of key-value pairs
[Int32], [Int]32-bit integers
[PsObject]PowerShell object
[Regex]Regular  expression
[ScriptBlock]PowerShell script block
[Single], [Float]Floating point number
[String]String
[Switch]PowerShell switch parameter
[TimeSpan]Time interval
[XmlDocument]XML document

Note: 

  • Windows PowerShell uses the Microsoft .NET Framework data types.
  • We don’t have to rely on PowerShell’s ability to automatically convert data types if we tell the interpreter that we are expecting a number as input.
  • This ensures that our script works as intended.
  • The explicitly declaring variable types can prevent unwanted results in your scripts and makes them more reliable.

PowerShell’s Variables

Windows PowerShell is designed to be an interactive command-line shell and it’s also a programming language. A PowerShell script is really nothing more than a simple text file. The file contains a series of PowerShell commands, with each command appearing on a separate line.

If we need to run the PowerShell script using the notepad then its filename needs to save as .PS1 extension.

Powershell Variables

Is It Case Sensitive

The answer is “YES”, power shell comments are case sensitive. 

  • As like other programming language, we need to declare the variable as like below. The main difference is we need to add prefix with ‘$’ symbol in the variable.
  • All we have to do to declare those variables is add a dollar sign, then use whatever name for the variable we want and no spaces are allowed in the variable name.

Example : 1

$name = 'Jon'
$number = 12345
$myGrade= 'D+'
$location = 'Charlotte'
// if we declare as string then it will treat as single word
$listofnumbers = 6,7,8,9

Example : 2

//Assign text to varible
$myFirstVarible = "Dotnet-helpers Welcomes you"
//Print the variable
$myFirstVarible 
//Concatenate Variable
$mySecondVarible = $myFirstVarible + "for PowerShell learning Curve" 
$mySecondVarible

Example : 3 Handling Dynamic Variables.

The Get-Variable cmdlet gets the PowerShell variables in the current console. You can retrieve just the values of the variables by specifying the ValueOnly parameter.

$UserAnna= “This is specific MSG for Anna”
$inputUser=”Anna"
$msgAnna = $(("User"+ $inputUser))
#-ValueOnly : Indicates that this cmdlet gets only the value of the variable.
Get-Variable -Name "$msgAnna" -ValueOnly

OUTPUT: This is specific MSG for Anna

 

Getting Help Information

The PowerShell includes detailed Help topics that explain PowerShell concepts. There are also Help topics for each cmdlet and provider and Help topics for many functions and scripts.

Getting Help for Cmdlets

To get Help about Windows PowerShell cmdlets, use the Get-Help cmdlet. Here let we see some of the cmdlets help.

To get a list of all the cmdlet Help topics in your session use below,

get-help -category cmdlet

OUTPUT

If we want to display one page of each Help topic at a time, then we need to use the help function or its alias man. For example, to display Help for the Get-ChildItem cmdlet, type

Man Get-ChildItem/Help Get-Childitem

If we need to known about all content in the Help topic, below cmdlet will help us with help of FULL keyword

get-help get-childitem -full

Getting Help About Providers

To get Help for a provider, type “Get-Help” followed by the provider name. For example, to get Help for the Registry provider, then type like below

get-help registry

To get all the list of provide use below

get-help -category provider

Getting Help About Functions and Scripts

We also use the help topics for many scripts and functions in Windows PowerShell. To display the Help for a function, type “get-help” followed by the function name.

get-help disable-psremoting

Getting Help Online

If we want to find the help online through the powershell then its can be acheive by the below command.

get-help <command-name> -online

For example, to get the online version of the Help topic about the Get-ChildItem cmdlet, type:+

get-help get-childitem -online

 

How to validate the version of installation

We can use $PSVersionTable.PSVersion to determine the engine version. If the variable does not exist is shown then it is safe to assume the engine is version 1.0

We also use,$Host, get-host , $PSVersionTable to get deep information about our power shell tool. Please find the snap for how to get the details.

What’s New With PowerShell

Windows PowerShell® 5.0 includes significant new features that extend its use, improve its usability, and allow you to control & manage Windows-based environments more easily. Windows Server 2012 R2 introduced the notion of Desired State Configuration, PowerShell 5.0 advances this concept through OneGet.

  • OneGet is a new module which way to search and install hundreds of software packages from the repository and this is known Chocolatey repository.
  • It is a package manager for Windows. It’s mission to be a framework for installing applications and tools that you need for a Windows computer.
  • It uses PowerShell to deliver packages built on the NuGet infrastructure.

Flow of using repository

  • List and manage software repositories for packages that can be installed.
  • Search and filter your repositories.
  • Install/uninstall packages from windows using the repositories.
  • Get started with the command: Import-Module -Name OneGet.

Installing Windows PowerShell in window’s 8.1

  • Windows PowerShell 5.0 is installed by default on Windows Server 2016 Technical Preview and Windows 10. 
  • To install Windows PowerShell 5.0 on Windows Server 2012 R2/Windows 8.1 Enterprise/Windows 8.1 Pro we need to download and install Windows Management Framework 5.0 here  
  • Don’t forgot to read the download details and meet all system requirements before starting your installation.

Windows Management Framework 5.0 Contains?

  • Contains updates for Windows PowerShell and Windows PowerShell ISE.
  • Package Management cmdlets.
  • Network Switch cmdlets.
  • Windows PowerShell Desired State Configuration (DSC)

To uninstall Windows Management Framework 5.0:

Navigate to the Control Panel\Programs\Programs and Features\Uninstall a program. You are looking for Windows Management Framework 5.0.

 

Windows PowerShell System Requirements

This topic we are going to discuss about the system requirements for Windows PowerShell 5.0 and its special features, such as Windows PowerShell Integrated Scripting Environment (ISE), CIM commands, and workflows.

Note:

Windows® 8.1 and Windows Server® 2012 R2 include all required programs so no need to install any thing special to work on powershell. This topic is designed for users of earlier releases of Windows. Windows PowerShell 4.0 runs on Windows 8.1, installed by default.

Operating System Requirements

  • Windows PowerShell 5.0 runs on the following versions of Windows.
  • Windows Server 2016, installed by default
  • Windows Server 2012 R2, install Windows Management Framework 5.0 to run Windows PowerShell 5.0
  • Windows Server 2012, install Windows Management Framework 5.0 to run Windows PowerShell 5.0
  • Windows Server 2008 R2 with Service Pack 1, install Windows Management Framework 5.0 to run Windows PowerShell 5.0
  • Windows 8.1 Windows 7 with Service Pack 1, install Windows Management Framework 5.0 to run Windows PowerShell 5.0

Microsoft .NET Framework Requirements

Windows PowerShell 5.0 requires the full installation of Microsoft .NET Framework 4.5. Windows 8.1 and Windows Server 2012 R2 include Microsoft .NET Framework 4.5 by default.

 

Introduction to Window’s PowerShell

Windows PowerShell is one of the most important Windows Server management tools that Microsoft has released. Windows PowerShell is one of the most important Windows Server management tools that Microsoft has released. An entirely new scripting environment for Windows, it consists of a new command shell and a new scripting language.We can write PowerShell scripts using any text editor, but you must need the PowerShell command shell for running.

Why its called Window Server Management?

Although PowerShell has been important in the Microsoft ecosystem ever since its release, as Windows Server 10 comes closer to release,we find that many features and deployments are significantly easier and more full-featured when carried out with PowerShell.  

How to get License?

PowerShell is built into Windows, so there is no fee or additional licensing cost. 

More about PowerShell:

Windows PowerShell is a command-line shell and scripting language designed specially for system administration. Built on the .NET Framework, Windows PowerShell helps IT professionals to control and automate the administration of the Windows operating system and applications that run on Windows Server environment. In PowerShell, administrative tasks are generally performed by cmdlets, specialized .NET classes implementing a particular operation. Sets of cmdlets may be combined together in scripts; executables, which are standalone applications; or by instantiating regular .NET classes.

Power shell versions: 

PowerShell VersionRelease DateDefault Windows Versions
2.0October 2009Windows 7 Windows Server 2008 R2
3.0September 2012Windows 8 Windows Server 2012
4.0October 2013Windows 8.1 Windows Server 2012 R2
5.0April 2014Windows 10

KnockoutJS – Environment Setup

It’s very easy to use KnockoutJS in our project by Simply referring the KnockoutJS Javascript file within the <script > tag in HTML pages like other script reference. We can access the Knockout.js in different ways like below

Referring Internally:

We can download latest version of the Knockout.js from its official website and add to our solution for making reference within out project.

<script type='text/javascript' src='knockout-3.3.0.js'></script>

Referring Externally:

We can refer the KnockoutJS library from CDNs and this can be achieved by following way.

Refering from KnockoutJS library from Microsoft Ajax CDN like below.

<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>

In another way can refer to a minified version of KnockoutJS library from CDNJS as below:

<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js" type="text/javascript"></script>

 

What do you think?

I hope you have idea of how to setup KnockoutJS in our Application. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

Knockout VS jQuery

Need to compare Knockout with jQuery?

Actual answer for above question is “NO”. Knockout.js is not a replacement of jQuery, Prototype etc.,. It doesn’t target to provide animation or AJAX functionality (Knockout.js can parse the data which received from an AJAX request). Knockout.js is focused only designed on data-driven UI. It is compatible with other client-side and  server-side technology.

Knockout.js uses a Model-View-ViewModel (MVVM) design pattern. In this, the model is react as data from back-end/business logic and the view is the visual representation of that data (UI) which is visible to the user and ViewModel acts as the intermediary between the model and the view.

In simple we can say the ViewModel is a JavaScript representation of the model data, along with associated functions for manipulating the data. Knockout.js creates a direct connection between the ViewModel and the view, which helps to detect changes from the mode and automatically update to the all the required changes in UI, in same way the update made in UI will automatically update to the model by the help of view model.

How to use Knockout ?

Simply reference to be made for the knockout file using a <script> tag in our your HTML pages. Let see below example,

<script type=’text/javascript’ src=’knockout-3.4.2.js’></script>

What is Knockout.js and how is it differ from jQuery?

What is Knockout JS?

Knockout is a JavaScript library that helps you to create rich, responsive UI and with clean data model. In other word, It is a javascript library that allows us to bind html elements against any data model. It provides a simple two-way data binding mechanism between our data model and UI.

Why Knockout?

The User interface(UI) data section will update dynamically when any changes had updated by user’s action or any external data update the Knockout is the best solution for simple to handle it. Its provide a simple mechanism to handle out data model and UI. For example if any changes made on data model are automatically it will reflect in the DOM(User Interface) and if any changes to on the DOM will automatically reflected to the data model.

With Simple Real time example

Let we discuss about with simple shopping cart Interface. If user add an item in the shopping cart, then it need to have to add the items from the data model and add the associated html element to the shopping cart. Finally the total price need to update in the UI. Consider the same scenario for the delete operation, same need to be update in all the scenario. So if we are not using knockout for doing this, then we need to write event handlers and listeners for dependent.

Let we conclude, the knockout will track all dependencies between the HTML and their underlying data and update dynamically(automatically) when update has made by user or from the back-end (update made by system side).

How is Knockout differ?

We all loves jQuery for its excellent way to manipulate elements and event handlers in a web page. But KO is solves a different problem. It is not a replacement of jQuery or other framework. It not target to provide animation, AJAX functionality or generic event handling. It is focused only on designing salable and data-driven interface.