Loading...

A quick demo of an advanced version Get-History cmdlet, which uses Out-GridView cmdlet that pop-up a GUI to select and executes multiple Get-History Command line items

A better Get-History in PowerShell - YouTube

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post A better Get-History in PowerShell appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Creating an HTTP triggered server less REST API using PowerShell hosted on Azure Functions to fetch top subreddit posts from Reddit.com posts

Serverless API using PowerShell in Azure Functions - YouTube

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post Serverless REST API using PowerShell in Azure Functions appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
Optical Character Recognition in Azure Cloud Shell

This post is in continuation of my previous blog post where I introduced PowerShell Module for Azure Cognitive Services, but today we are covering Optical Character Recognition in Azure Cloud Shell

This module is a PowerShell wrapper around Microsoft Azure Cognitive Services REST API’s, to bring the power of Machine Learning to your console and applications.

Full Project is open sourced and hosted on GitHub and is also downloadable from PowerShell gallery

The following video demonstrates the below-mentioned steps, just copy paste this code into your Azure Cloud shell and see the magic


Optical Char Recognition from Setup to Execution in Azure Cloud Shell under 2 mins - YouTube

I’m excited to see how this project will evolve in the future, let me know if you have any feedbacks.

On this note, please stay tuned for future posts … signing off…

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post Optical Character Recognition in Azure Cloud Shell under 2 mins appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
Introduction to “PowerShell Module for Azure Cognitive Services”

PowerShell wrapper around Microsoft Azure Cognitive Services REST API’s, to bring the power of Machine Learning to your console and applications.

Microsoft Cognitive Services offer machine learning/Artificial intelligent models to be accessed through REST API’s to give Human-like cognition abilities to your applications.

Following are the cmdlets that are included in this module.

  • ConvertTo-Thumbnail – Converts an image to a smaller image or Thumbnail
  • Get-Face – Identify face & facial feature and ability to detect age, gender, emotion.
  • Get-ImageAnalysis – Analyze image and return color, tones, image type and metadata
  • Get-ImageDescription – Describes image with tags and captions
  • Get-ImageTag – Tag image and convert to hashtags
  • Get-Imagetext – Optical character recognition abilities to convert text in the image to plain text
  • Get-KeyPhrase – Identifies key phrases in a string
  • Get-Sentiment – Return sentiment scores for a respective string 1 being the positive and 0 being negative
  • Search-Entity – Search Entities like celebrities on Bing and return the results
  • Search-Web – Ability to search the internet for a query, web pages, URL, snippets are returned as a result
  • Test-AdultRacyContent – Moderates content for any Adult or Racy and return results if the manual review is required.
  • Trace-Language – Detects language used in a string and returns language code.

Github Repository: 

https://github.com/PrateekKumarSingh/PSCognitiveService


PowerShell Gallery:   Module in action: 

PowerShell Module for Azure Cognitive Services | RidiCurious.com - YouTube

Samples:

The project is still in a very premature phase and since I’m actively involved in the development gradually, more cmdlets for Speech, LUIS (Language Understanding Intelligent Service), custom Image and video search will be introduced.

I believe can be easily used in PowerShell bot frameworks like PoshBot for ChatOpsAzure Functions and from Azure CLI.

I’m excited how this project will evolve into future. On this note, please stay tuned for now… signing off…

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post PowerShell Module for Azure Cognitive Services appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
4 ways to select Unique items in Powershell

Following are the approaches that I could come up with, there may be few more, feel free to point them out and I’ll update the article

  1. Using Select-Object Cmdlet: This is probably already your favorite way to find unique items in PowerShell

  2. Using Get-Unique Cmdlet: The catch with this cmdlet is – it only works with sorted objects by comparing adjacent items.

  3. Using [HashSet<T>]:  HashSets are data structures that only hold unique items, you can typecast your array in our example to a [HashSet]I was not aware of .Net provides a class for HashSets, which I learned a few weeks back and to my wonder, they seem to be better in performance.But in case you are worried, typecasting to HashSet will change data type and you can’t perform methods available in that type, then please be aware that you can typecast them back to System.Array like in the below image.

  4. Using LINQ: Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language, and it can be used directly in PowerShell

NOTE: The performance varies in all 4 approaches, in the following screenshot you can clearly see the difference, the use of pipeline probably slows down the cmdlets – Select-OBject and Get-Unique.

If you like this article read more similar articles under ‘N – Ways to’ category

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post 4 ways to select Unique items in PowerShell appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
Introduction to Part 3 of “PowerShell Scripting guide to Python: Data Structure”

This is the third article in “PowerShell Scripting guide to Python” blog series and we are covering Data Structure today.

If you are new please refer to the  part-1 of this blog series for Python prerequisites and the introduction of this series

What has been covered already?

Till now we’ve covered the following topics…

Overview

In this article, we’d be covering following topics –

  • Arrays, List and ArrayList
    • Creating Array, lists, and ArrayLists
    • Empty lists
    • Adding elements
    • Reversing array elements
    • assigning array elements to multiple variables
    • Accessing elements of the array using indexing
    • Accessing elements of the array using negative indexing
    • Find length the of an array
    • Modifying elements using index
    • Append/insert elements at an index
    • Removing elements of an array
    • Array Slicing
    • Two-dimensional Array\list
  • Tuples
    • Creating Tuples
    • Use cases
  • Hash tables and Dictionaries
    • Hashtable with integer keys
    • Accessing elements of a dictionary
    • Adding key-value pairs or replace any existing key
    • Get dictionary keys or values
    • Iterating through key-value pairs
    • Deleting a key-value pair
    • Created nested dictionary
    • Accessing nested dictionary items
    • Sorting a dictionary
  • Sets
    • What is a Set
    • Example
    • Usecase
Arrays

PowerShell array is immutable (fixed sized) Data Structure that can hold heterogeneous elements.

Arrays in Powershell are implicitly typed, but in case you want to create a strongly typed array, cast the variable as an array type, such as string[], long[], or int32[]

Python doesn’t have a native array Data Structure, hence Arrays are supported by the array module and need to be imported before using them.

The elements stored in an array are restricted or constrained by their data type are Homogeneous in nature. That means a character array can only store character elements.

The data type is specified using a type code during the array creation, which is a single character like one of the following-
 
Example –
Key Pointers
  • PowerShell Arrays
    • Immutable
    • Homogeneous or Heterogeneous
    • Loosely typed
    • Built-in
  • Python Arrays
    • Mutable
    • Homogeneous
    • Strictly typed
    • Not built-in and have to be imported
    • Generally comparatively faster and efficient than arrays (* depends on use cases)
ArrayList (.Net)
Key Pointers
  • PowerShell (.NET) ArrayList
    • Mutable
    • Homogeneous or Heterogeneous
    • Loosely typed
    • Built-in
Lists

A list in Python is just an ordered collection of heterogeneous item types and is dynamically(size can change) mutable – add, delete, insert

Key Pointers
  • Python List
    • Mutable
    • Heterogeneous or homogenous items hence can be used as Arrays
    • Loosely typed
    • Built-in into Python
    • Generally comparatively slower than arrays (* depends on use cases)
Operating with PowerShell Array[List] vs Python Lists
  • Finding Length

    PowerShell Arrays have a property ‘Length’ which can be accessed using the (‘.’) Dot operator to get the Length (number of elements) of the array

    Whereas, Python Array’s length is calculated using the Built-in function called len()

  • Indexing and access/modify elements

    PowerShell and Python are Zero indexed, that means the first element of a PowerShell Array or Python List has index 0.

    Array/List index can be used in square brackets [index] to access and modify elements like in the following examplesModifying an element is technically Variable assignment to an array/list index.

  • Insert/Add elements

    Adding an element in PowerShell ArrayList is done by .add() method, whereas element insertion is achieved by the .insert() method in both PowerShell and Python.

    Python List uses .append() method to add elements at the end (last index) of the List.

  • Reverse elements

    PowerShell [Array] Type accelerator has a built-in method to reverse() the elements of an array.

    Similarly, Python has a reversed() method which can reverse the order of List elements.

  • One to Many: Array to the Variable assignment

    PowerShell and Python both offers One to Many: Array/List to variable assignment

  • Remove elements

    PowerShell and Python both allows you to remove Array/List elements at a specific index, and by value, following are some examples

  • Array/List slicing

    Array slicing in PowerShell and Python is just like String Slicing which we covered in previous blog post.

    PowerShell syntax-

    array[startindex..endindex]

    Python syntax-

    array[startindex:end:step]
    Here,
    end = EndIndex+1
    step = Increments

  • Multi Dimensional Array/List

    Python and PowerShell both enable you to create multi-dimensional arrays and syntax to create one is exactly same.

Tuples

Tuples are immutable (constant) Data Structure support in Python and PowerShell, unlike lists or array lists which can be modified.

Once a Tuple is defined you cannot delete, add or edit any values inside it.This can be very helpful in use cases where you might pass the control to someone but you do not want them to edit or manipulate data in your data structure, but rather maybe just perform operations separately in a copy of this Data Structure.

PowerShell –

Defining Tuples in PowerShell requires you to use .NET classes or [System.Tuple] type accelerator

Python –

Whereas, use () parenthesis to define a tuple in Python.

Sets

Sets are a collection of distinct (unique) objects that only hold unique values in the dataset.

A set is an unordered collection but a mutable one(can be modified)

Sets are very helpful when going through a huge dataset and want to find Intersection, union and other data sets.

PowerShell utilizes .Net class System.Collections.Generic.HashSet<T> to create a HashSet

Whereas, Python has an inbuilt method set() to define sets.

HashTables and Dictionaries
Hashtables or Dictionaries are Data Structure that are made up of Key-Value pairs, ‘key’ is used to identify an item which holds a ‘value’
PowerShell-
Define PowerShell hashtables using ‘@’ following open and closing ‘{}’ braces, and semi-colon to separate the key-value pairs

Python-

Whereas, in Python, you can define Dictionaries using open and closing ‘{}’ braces and comma (,) to separate the key-value pairs

HashTables/Dictionary operations
  • Accessing Key-Value pair

    A key value pair of hashtable\dictionary in PowerShell and Python is accessed by name followed by key inside ‘[]‘ brackets

    PowerShell-

    Python-

  • Adding Key-Value pair

    Powershell uses .add() method to add key-value pairs, whereas in Python you can directly assign a value to keys like variable assignment

    PowerShell-

    Python-

  • Find Keys and Values

    Find all keys or values use ‘key’ and ‘value’ property of hashtable in PowerShell, whereas key() and value() methods are used in Python for same.

    PowerShell-

    Python-

  • Iterating through key-value pairs

    In some usecases you’ll want to iterate the key-value pairs in a hashtable or a dictionary, following are some examples to demonstrate that.

    PowerShell-

    Python-

  • Deleting a key-value pair

  • Create and access nested hashtables

    Just like PowerShell, you can create nested dictionaries [dictionary in a dictionary] in Python

    PowerShell-

    Python-

  • Sorting hashtable

    Sort Hashtables in PowerShell and Dictionaries in Python if required.

    PowerShell-

    Python-

Hope you enjoyed reading this article and let me know your feedback.

In Part-4, ie, the next article of this blog series, we would be covering Loops and Iterations hence, please stay tuned!

More from this Series-

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post PowerShell Scripting guide to Python : Part-3 | Data Structure appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
Introduction to Part 2 of “PowerShell Scripting guide to Python”

This is the second article in “PowerShell Scripting guide to Python” blog series.

If you are new please refer to the  part-1 of this blog series for Python prerequisites and to get an idea of what has been covered.

The whole idea of this series is to make to link your existing knowledge of Powershell with new concept\syntax of Python as fast as possible.

In fast-changing IT scenarios to DevOps to Future (Data Science, AI, and Machine Learning) python is a must know.

We are covering following items in this article today

Overview
  • Date and Time
    • Get Date and Time
    • DateTime formatting
    • Time Span or Time Delta
  • Strings
    • Single, Double and Triple quoted strings
    • String interpolation or variable substitution
    • Escape characters
    • Common string operations
    • String formatting
    • Substring or string slicing
    • Built-in string methods
Date and Time
  1. Getting Date and Time

    Retrieving date and time in PowerShell is as simple a cmdlet Get-Date or using the [datetime] type accelerator

    But, Python date and time requires you to import time or datetime modules

  2. DateTime formatting

    Both PowerShell and Python provides Date and Time formatting with formatting codes.
    Please find cheatsheets to the format codes in the following links

    PowerShell date time string format codes
    Python date time string format codes

    Achieve desirable date-time formatting by utilizing these Format codes.

    PowerShell-

    Python-

  3. Time Span or Time Delta

    In Powershell, a TimeSpan is a duration expressing the difference between two dates, time, or datetime.
    TimeSpan can be used in multiple use cases like calculating a future or a past date

    But, TimeDelta() is Python implementation of a TimeSpan which works exactly like [TimeSpan] with slightly different syntax

Strings and String Manipulations

Strings are most popular data types in Python can be created by simply enclosing characters in a single or double quote.

  1. Single, Double and Triple quoted strings

    Single, double or triple quotes. Single quotes (‘) are used to create strings in Python, but Single Quotes are treated the same as double quotes (“) or triple-quoted string is used for creating multi-line strings.

  2. String interpolation or variable substitution

    String interpolation or variable substitution is achieved by Double quotes in PowerShell

    Python utilizes something called f-strings which were introduced in Python v3.6.

    In Python, we use F-strings for variable substitution

     

  3. Escape characters

    Backslash ‘\’ is a representation of Escape characters in a Python string and can be interpreted in a single, double or triple quoted strings.

    Unlike Powershell which represents Escape character by backward apostrophe/grave ‘`’
    PowerShell does not interpret Escape characters in Single Quotes, but only in Double quotes.

  4. Common string operations

    Common string operations in PowerShell and Python are almost similar

    Python –

    PowerShell –

  5. String formatting

    PowerShell provides a ‘-f’ operator called the Format operator to perform string formatting.

    Python has a similar Built-in .format() method for formatting the strings.

  6. Substring or string slicing

    Achieve Substring slicing or extracting from a Powershell string by

    Using Range operator


    Using Substring() method

  7. Built-in string methods

    Python and PowerShell provide built-in methods for string manipulations, which are up to some extent similar in functionalities.

    Powershell

    Python

Hope you enjoyed reading this article and let me know your feedback.

In the Part-3 of this blog series, we would be covering Data structures – List, Tuple, Dictionary, and Loops hence, please stay tuned!

More Articles from this Blog series –

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *

The post PowerShell Scripting guide to Python : Part-2 appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

PowerShell scripting guide to Python | Data TypeCasting - YouTube

Understanding Data TypeCasting in PowerShell and Python

Full article | Facebook | Twitter 

The post [Video] PowerShell scripting guide to Python | Data Typecasting appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction to Part 1 of “PowerShell Scripting guide to Python”

Interested Powershell developers can learn Python and benefit from this blog series. Python which is one of the top programming languages in the world and needless to talk about its importance and role in the world of development and infrastructure. PowerShell Scripting guide to Python would be helpful for you if you know PowerShell already.

It is designed to make you familiar with new concepts, syntax, and semantics of python so that you can totally relate to the concepts of PowerShell already in your arsenal, and learn this language fast.

Going forward in this series, we will talk about similarities and some differences. Purpose of this series is not to prove which language is better, hence I’ll leave you to judge benefits and drawbacks of PowerShell and Python over one another.

Prerequisites:
  • Install Powershell v5.1
  • Install Python v3.6.1 – I’m using Anaconda that has Python and bunch of other useful Python packages that come pre-installed, and here is a link to the Anaconda user manual if you want to download that.
  • Set  Environment variable PATH to point to the folder that has Python executable (Python.exe)
  • [Optional] I’m using Visual Studio Code as an editor for both PowerShell and Python
Overview:

In this part, we will cover following items –

  • Version Info
  • Case sensitivity and indentation
  • Comments
    • Single-line comments
    • Multi-line comments
  • Variables
  • Console I/O
  • Object Introspection – methods and properties
  • Help System
  • Module
    • Importing
    • installing
  • Checking data types
  • Data Typecasting
  • Saving and running commands as a script
  • Passing command-line arguments to a script
  1. Checking Version Information

    The version is probably the first thing we learn to check in PowerShell, using the automatic variable $PSVersionTable


    While in python the version automatically appears when you launch python shell or call the python executable with the switch –version

    There would be scenarios where you want to check Python version dynamically during the code execution, for which you can import sys module and check the version_info attribute

  2. Case Sensitivity and Indentation

    Powershell is case-insensitive scripting language but Python is strictly case-sensitive, hence same keywords or names with a different case(s) are understood differently by the compiler.

    Python is also strongly indented. Indents provide structure to the program and differentiate code blocks from one another.

    In PowerShell Indentation is a matter of style, whereas in Python Indentation is a language requirement.

    Following example demonstrates Python and Powershell codes with indentation,

    and the below example shows how indentation is important in a Python program.

  3. Comments

    Single line comments Python is a Hash sign (#) followed by the comment, which is exactly what we are familiar in PowerShell, Whereas, Python multiline comments starts and ends with triple single or double quotes.

  4. Variables

    No need to specify Data types explicitly in the variable declaration in Powershell or Python, as both are Dynamically typed programming languages.

    Following rules apply when naming Python variables

    • The first character can be the underscore “_” or a capital or lower case letter.
    • Following the first character can be anything which is permitted as a start character plus the digits.
    • Since Python is case-sensitive so are the variable names!
    • Python keywords are not allowed as variable names

  5. Console Output

    Python provides a print() function to print output to the console. Just like Write-Host cmdlet in PowerShell, in fact in PowerShell, it’s much simpler and we can directly output string to the console.

    But, there is a catch, Write-Host sends output directly to the console.

    Strings inside quotes are sent to a different PowerShell Stream called Output stream (the default PowerShell stream) , which can be piped and be used by cmdlets following the pipeline or can be stored in a variable.

  6. Console Input

    User input can be captured using the input() function  in Python

    and in PowerShell, we use Read-Host cmdlet to get user inputs

  7. Object Introspection

    In PowerShell to introspect members of an object we pass the object to Get-Member cmdlet

    and in Python, you can use a built-in function dir() to list attributes and methods of an object

    Get the members of an object using Python library ‘inspect‘ .

  8. Help System

    PowerShell provides a very robust help system through Get-Help cmdlet, where we can see examples and understand how PowerShell works.

    Python Help system is accessed with the inbuilt method help().

  9. Modules
    1. Importing ModulesPowerShell Import-module Cmdlet is to import modules in the current session, whereas Python Provides a keyword import
    2. Installing Modules
      Installing modules in python using PIP Package manager which downloads and installs packages from an online repository
  10. Checking data types

    Powershell Objects provide an inbuilt function GetType() to check the data type

    Similarly, in python, we can use the type() inbuilt method to test/check the data type

  11. Type conversions

    Sometimes it’s necessary to perform conversions between the built-in types. To convert between types you simply use the type name as a function in Python.

    PowerShell provides type accelerators to typecast data types

  12. Saving and running a script

    PowerShell scripts have extension .ps1 and .py extension for the Python programs 

    In order run a script in python you can call thePython executable (python.exe)  with filename\path like in the below image.

  13. Passing command line arguments to a Python script

    Argv attribute of sys module in Python provides the list of command-line arguments passed to the Python program.

    It’s basically an array holding the command line arguments of our program.

    Don’t forget that the counting starts at zero 0, not one 1 and by default the first argument, sys.argv[0], is always the name of the program where it was invoked.

Hope you enjoyed reading this article and let me know your feedback.

In the Part-2 of this blog series we would be covering String manipulations hence, please stay tuned!

Blog Series

Till now we’ve covered the following topics…

Follow @SinghPrateik

Subscribe to our mailing list
* indicates required
Email Address *


The post PowerShell Scripting guide to Python : Part-1 appeared first on Ridicurious.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview