Tag Archives: dotnet-helpers.com

How to get the array as input using Powershell

To read an array into Read-Host (get the array as input), you would need to put it in a loop because anything entered into Read-Host will be interpreted as a string. To make output in new line we can use $OFS, which is a special variable in PowerShell . OFS stands for Output field separator . You would use this to separate object/Array.

The .split() method is self explanatory, the .trim() method will simply remove leading and trailing spaces and leading and trailing line breaks

Example #1 : Getting Value as an Array by Looping

$arrayInput = @()
do {
$input = (Read-Host "Please enter the Array Value")
if ($input -ne '') {$arrayInput += $input}
}
#Loop will stop when user enter 'END' as input
until ($input -eq 'end')

$arrayInput

OUTPUT:

Example 2# : Alternative approach for handling the multiple inputs without loop.

#Set New line using OFS special Powershell variable
$OFS = "`n"
#Externally set input value as string
[string[]] $_ServerList= @()
#Get the input from the user
$_ServerList = READ-HOST "Enter List of Servers"
#splitting the list of input as array by Comma & Empty Space
$_ServerList = $_ServerList.Split(',').Split(' ')
$OFS + $_ServerList

Output:

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>