Welcome to My WeBlog.

Hello there,

I am glad that you are here! I am really excited to start this blog and is all about PowerShell along with other technical stuff. The posts I blog here are truly from my personal experience and for my future reference. So I strongly recommend before you try anything from this blog directly on your production environment, please do it on your test environment first. You’re always welcome to leave your comments, suggestions, and question about my blog posts on my contact page.

Thank you & Keep visiting my blog!

Azure: Know your Azure VM created date using PowerShell & AzCli.

Do you want know when was your Azure VM created? Then this script will retrive date time created for the given Azure VM(s). Not sure whether there is direct way to retrieve the VM created date, but I couldn’t find any CmdLet to know the VM created date.

However, I have written a PowerShell function to know the VM created date by considering the VM OS disk creation date as VM creation date.

The function accepts the combination of Resource Group Name and VM Name as mandatory parameters or VM object(s), and you will see the output as below…

Screenshot from 2019-09-25 22-21-12

And, here is the script…

And even I have tried the same using Azure Cli as well, and it worked like this…

And you get the output like this

Screenshot from 2019-09-26 09-30-03

Thank you.


PowerShell – Get Windows Activation Status across the plant.

One of my friends who is working for a retail store company as a sysadmin was seeking my help in finding the windows server activation status across his organization. Of course, there are many ways to fetch the windows activation status and there are plenty of tools are available online. But I have used CIM Instance with WIM class ‘SoftwareLicensingProduct’ to fetch the activation status for the given server list, and here is the code snippet…

And you will get the status as below…


Thank you.

Windows Terminal and my customization, it’s awesome.

Ever since I started working with Windows Terminal for my PowerShell work, I feel like I live in a royal world, I just simply love it.

Windows Terminal is a terminal emulator for Windows 10 starting from version 18362.0 or higher, and it supports Windows PowerShell, PowerShell Core, Command Prompt, Windows Subsystem for Linux (WSL) & Azure Cloud Shell. As of now, it is not detecting PowerShell 7 Preview but you can add it manually. Windows Terminal enabled with the rich tabbed view and can easily switch between the consoles/terminals with pre-defined short keys.

I have customized my Windows terminal pretty much to go along with PowerShell Core as my default terminal and of course along with all other terminals as well.

Windows Terminal Installation

Windows Terminal is available via Windows Store, and you can download it by clicking here. It can only install on Windows 10 version stating from 18362.0 or higher, and still it is in the preview version and an open-source project available on GitHub.


Now let’s see how I customized for my Windows Terminal for PowerShell Core along with all other terminals…

Windows Terminal first look right after the installation…


It detected PowerShell Core, Windows PowerShell, Command Prompt and Azure Cloud Shell. Since I have already installed Ubuntu, Debian & Kali-linux WSL, they are also showing up along with the other terminals.

Windows Terminal Customization

By default, it will pick up Windows PowerShell, PowerShell Core, Command Prompt and any WSL is already installed & Azure Cloud Shell, but it will not detect PowerShell 7 Preview. However, you can add it manually…

All the settings and configurations happen through JSON format associated with the windows terminal available in the AppData local folder, and you can take a look here.

Configuration 1: Add PowerShell 7 Preview

You can open the settings file by pressing ctrl+, or click on the WindowsTerminal2 button on top of the Windows Terminal and then click on Settings, and the JSON file will be opened with your default code editor.

If you take a look at the JSON file, every terminal has a separate profile with a bunch of settings to be modified as per your need, and the profile for PowerShell Core looks this…

"acrylicOpacity" : 0.5,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "C:\\Program Files\\PowerShell\\6\\pwsh.exe",
"cursorColor" : "#FFCCFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
"name" : "PowerShell Core",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false

From the settings above, you can you customize the settings like Opacity, Colors, Font and pretty much all you can set as per your need.

Okay now, by using the above profile let’s add PowerShell 7 Preview to Windows Terminal, and the profile looks like this which you can add in the JSON file under profiles section…

"acrylicOpacity" : 0.5,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
"cursorColor" : "#FFCCFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{77e7e60a-38e6-45fb-9c5a-44510c02c4e4}",
"historySize" : 9001,
"icon" : "C:\\Program Files\\PowerShell\\7-preview\\assets\\Powershell_av_colors.ico",
"name" : "PowerShell 7 Preview",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false

If you notice the settings from the above, I have modified commandline, guid, icon and name

Generate the new guid using New-Guid PowerShell CmdLet.

That’s all, the settings will be applied right after the file is saved, and it doesn’t require to close and reopen the terminal to take any effect, it’s on the fly, you can see the PowerShell 7 Preview in the tab drop-down list including the PowerShell &7 icon.



Configuration 2: Setting the background image

I like the most in the Windows Terminal is the background image, and it gives me a different and pleasant feel when I am working with, now let’s see how to add the background image…

"backgroundImage" : "ms-appdata:///roaming/yourimage.jpg",
"backgroundImageOpacity" : 0.75,
"backgroundImageStrechMode" : "fill",

the above 3 keys will do the magic for you, give the path of the image, set the opacity and the strech mode. You can use image or gif as well, and the strech mode you can use uniformToFillbesides fill. My settings are as below…

"backgroundImage" : "C:\\Users\\kiran\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\SurrealWallpaper.jpg", 
"backgroundImageOpacity" : 0.25, 
"backgroundImageStrechMode" : "fill",

And it looks this…


You can still play around with the GIF images, Opacity settings, and color schemas.

Configuration 3: Setup the default terminal

Since I work with PowerShell especially PowerShell 7 Preview, I want to make my PowerShell 7 preview is my default terminal when I open the Windows Terminal. Let’s see how it can be done…

Go to settings, and find the key defaultProfileunder globalssection…

“defaultProfile” : “{2d647fbe-310d-4d05-852f-8f664e6f490c}”,

Currently, PowerShell Core is my default profile, and to make PowerShell & preview as default, you need to replace the guid of PowerShell Core with guid of PowerShell 7 Preview (You can find it under PowerShell 7 Preview profile) in the defaultProfile.


Configuration 4: Other Settings

Under each profile, there are various settings to change the behavior of the terminal, now let’s see a few…

"acrylicOpacity" : 0.5,
"useAcrylic" : true

These settings will apply background transparency to the terminal window. Note this setting will work only on physical machines, not on VMs.

"colorScheme" : "Campbell"

Color Scheme will change the look & feel of the terminal by applying different colors, by default there are 5 color schemes are available in the settings file, and also you can add different scheme of your own choice.

"fontSize" : 14,

You can set the default font size, and you can change the font size by using ctrl + mouse wheel, like scroll up increases and scroll down decreases the font size directly from the terminal itself.

There are few other where you can give it a try.

In addition to the above customization, I tweaked my profile inside the PowerShell and now it looks like this when I open my Windows Terminal every time…


You can glance at my sample profile here.

Thank you.

PowerShell – Run cmdlets without installing the modules – Implicit remoting in PowerShell

All the IT administrators they work with remote computers as part of their regular activities, and most of the time they use explicit remoting by mentioning the -Computername parameter to the cmdlets, and most commonly used cmdlet is Invoke-Commandalong with the other cmdlets like Get-Service, Get-Process, Get-WmiObject, Get-EventLog and etc…

Invoke-Command -ComputerName Server -ScriptBlock { $env:COMPUTERNAME }
Get-Service -ComputerName Server -Name servicename
Get-Process -ComputerName Server -Name processname
Get-WmiObject -Class Win32_OperatingSystem -ComputerName Server
Get-EventLog -ComputerName Server -LogName Application -Newest 5

What is Implicit Remoting in PowerShell?

Bring the modules installed on the remote computer and import them on your local computer to run the cmdlets natively as if they are installed on your local computer. But in fact, the cmdlets run against the remote computer from which the module is imported.

We need to establish a connection to the remote computer, then load the required modules into the remote session and then export the session modules to our local computer.

Establish the remote computer session

Open a PowerShell session with elevated privileges and create a new pssession to the remote computer from which you want to import the module…

$dcsession = New-PSSession -ComputerName DC2K16

The session output will be as below…


 Id Name            ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            ------------    ------------    -----         -----------------     ------------
  1 WinRM1          DC2K16          RemoteMachine   Opened        Microsoft.PowerShell     Available

The above command to establish the connection to the remote computer works with the computer connected to the same domain, if it is not connected to the domain or from a different domain you need to add the remote computer name or IP to your local computer’s WinRM TrustedHosts list, and pass the credentials using -Credential parameter to the cmdlet.

Load the required module into the remote session

Basically, I want to connect to my DC server and export the ActiveDirectory module to my local session…

Invoke-Command -Session $dcsession -ScriptBlock {
Import-Module -Name ActiveDirectory

The module is loaded in the remote session and it is ready to export into the local PowerShell session.

Export the module from remote session to the local session

You can export the module with a different name altogether and also add a prefix to the cmdlets at the time of loading the module. When you export the module it will be created under $env:PSModulePath.

Export-PSSession -Session $dcsession -CommandName *-AD* -OutputModule RemoteDCModule -AllowClobber

    Directory: C:\Users\kiran\Documents\WindowsPowerShell\Modules\RemoteDCModule

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       05-02-2019  10:32 PM             99 RemoteDCModule.format.ps1xml
-a----       05-02-2019  10:32 PM            594 RemoteDCModule.psd1
-a----       05-02-2019  10:32 PM         396254 RemoteDCModule.psm1

Exporting the module is nothing but the PowerShell creates functions by default with the name same as the cmdlet name to execute on the remote computer where the module is exported from, and then wraps up all these functions into a proper script module(.psm1) ready to import.

Import the module and run the cmdlets

The exported module is ready to be copied and imported on any computer, provided the computer can be connected to the remote server. When you import the module and run the cmdlet for the first time within the session it will create a new pssession to the remote computer and then executes the command, and the same pssession will be used till the current session alive.

# Without prefix
Import-Module -Name RemoteDCModule

# With prefix
Import-Module -Name RemoteDCModule -Prefix FromDC

Adding prefix will help us to identify the cmdlets easily, it’s not mandatory though.

# On the remote computer
Import-Module ActiveDirectory
Get-Command -Module ActiveDirectory | Select-Object -First 4

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-ADCentralAccessPolicyMember              ActiveDirectory
Cmdlet          Add-ADComputerServiceAccount                 ActiveDirectory
Cmdlet          Add-ADDomainControllerPasswordReplicationPolicy    ActiveDirectory
Cmdlet          Add-ADFineGrainedPasswordPolicySubject       ActiveDirectory

Notice the CommandType is CmdLet on the remote computer when you actually import the module.

# On the local computer, import the exported module with prefix
Import-Module RemoteDCModule -Prefix FromDC
Get-Command -Module RemoteDCModule | Select-Object -First 4

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Add-FromDCADCentralAccessPolicyMember              1.0        RemoteDCModule
Function        Add-FromDCADComputerServiceAccount                 1.0        RemoteDCModule
Function        Add-FromDCADDomainControllerPasswordReplication... 1.0        RemoteDCModule
Function        Add-FromDCADFineGrainedPasswordPolicySubject       1.0        RemoteDCModule

Here the CommandType is Function and also notice the prefix FromDC in the noun. As I mentioned earlier, PowerShell creates a function to execute the actual command using Invoke-Command on the remote computer. If you want to know more about how the function is created, then pick any function from the exported module and see the definition of it using the command below…

# Syntax
(Get-Command -Name [function-name]).Definition

(Get-Command -Name Get-FromDCADUser).Definition

Execute the CmdLets

Since the exported module is saved in the local filesystem, you don’t need to create the remote computer session every time you execute the commands, the module will take care of establishing the connection to the remote computer and execute the commands against. So you can remove the remote session…

Remove-PSSession -Session $dcsession

Now, run any command and notice that there is a new session will be created (highlighted below)


So finally to justify the title of this post, you can run the cmdlets without installing the modules on the local computer. Especially it is much helpful on PowerShell Core, because some modules work with Windows PowerShell don’t work with PowerShell Core.

Azure – Host a static website in a storage account using Azure PowerShell.

What is a static website?

By the definition, the static website contains web pages with fixed content and displays the same content to every user on every visit, and static websites are very basic and easy to create.

Now static websites can be built using HTML, CSS and JavaScript and hosted on Azure Storage, and support client-side script execution but not server-side, if the static website needs some data processing or manipulation on server-side you can leverage it to Azure Cognitive Services or Azure Functions.

What is the use?

Static websites are very useful when it doesn’t require high bandwidth, backend support and targeted to limited audiences and mostly for the shorter duration of time.

Some useful areas are…

  • Explain about the project and the roadmap.
    • Just for the sake of presentation in the meeting, create some html documents with the necessary content, upload them to the Azure blob storage and simply access the url from anywhere in the world.
  • Showcase about the products, events and promotions.
    • Sales and marketing teams require nice and colorful web pages to walk through the concepts, so build a website using CSS & HTML, publish it on to Azure blob storage and share the link with the intended audience.
  • Technical Documents & Manuals
    • Host some technical documentation and manuals relating to your project, and share it with the team across the globe for their perusal.

How it works?

When the static website service is enabled on a Azure storage account you need to enter the default document name; and error document name as optional and when the feature is enabled a container named $web will be created if it doesn’t already exist to upload your website files. Files in the $web container are read only, case sensitive and available to access anonymously

How to access?

Available to the public web following this pattern:

Available through a Blob storage endpoint following this pattern:

It can also available with CDN and SSL support and custom domain name as well.

What is the pricing?

Azure Static website feature is free; the pricing is only for storage. But in addition to the storage costs, data egress will apply and in case Azure CDN is enabled to use a custom domain with an SSL certificate, that will also be applicable.

How to enable the Static Website feature and host a website using Azure PowerShell?

All you need is a valid Azure subscription and follow the steps (in PowerShell)…

  • Login into Azure account.
  • Select the required subscription.
  • Select/Create a Resource Group.
  • Select /Create a Storage Account (StorageV2).
  • Set the current storage account to enable the Static Website feature.
  • Enable the Static Website feature on the current storage account.
  • Upload the website files to the blob storage container ($web).
  • Verify the files uploaded successfully.
  • Retrieve the URL to access the static website.

With the glory of GitHub public repositories, I have cloned a simple website and created my profile page just like that and hosted it on my Azure Storage.


PowerShell – How to use splatting to pass parameters to commands

Many a times we might have come across the situation where we need to execute the lengthy CmdLets/functions having bunch of parameters and exceeds screen width and wrapped down to the next line or need to scroll towards end of the command or need to ignore the new line using the escape character (`).

Splatting, pass the parameter values as a collection in the form of name and value pair, as a hash table or array of values. It makes the command shorter, easy to read and can be re-used. It’s a hash table/array variable though, to pass the paramater values to the command @ sysbol will be used before the variable name instead of $.


$paramtable = @{
Name1 = 'Value1'
Name2 = 'Value2'
Name3 = 'Value3'
C:\> Sample-Command @paramtable
C:\> Sample-Command <optional parameters> @paramtable <optional paramaters>

To provide the named parameter values hash table can be used and to provide the positional parameters array can be used. When splatting, it is not necessary to use either hash table or an array only to pass the parameters, positional parameters and/or named parameters can also be used along with.

EXAMPLE: Splatting with hash table

Create a new file using New-Item CmdLet by passing necessary parameters…

EXAMPLE: Splatting with array

Copy a file from one location to other using Copy-Item CmdLet by passing necessary parameters…

An another example…

Just a tip #5 – Select-Object with calculated properties in PowerShell

Sometimes the value from the output might not be in the readable format, the header might be not appropriate for the value or the value is not straightforward, and sometimes there is a need of calculated field altogether…

# Get the total memory in GB from the local computer using the calculated property with Select-Object
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property PSComputerName, `
@{Name = 'Memory in GB'; Expression = {[Math]::Round($_.TotalVisibleMemorySize/1MB)}}

# Get the services where the names are starting with App, and display IsRunning with Yes/No using the calculated property
$IsRunning = @{
Label = "IsRunning"
Expression = {
if($_.Status -eq 'Running') { "Yes" }
else { "No" }
Get-Service -Name App* | Select-Object -Property Name, DisplayName, $IsRunning



Excel reports using ImportExcel module from PowerShell Gallery.

You know why Excel is still one of the popular reporting tools because it is very easy to use, customizable as per your needs and moreover it is interactive. There are many ways that you can generate excel reports programmatically, but especially when you are using a scripting language like PowerShell there are tons of modules are already available with sophisticated features in the public repositories to reuse in your code, and they are very easy and simple to use.

Please be careful when you are installing the modules from the public repositories, because people around the world they publish their code into the repositories which work for them as per their environment and settings, but it may harmful for your environment. So please ensure the scripts work fine for you in your test environment first and then use it in your production environment.

ImportExcel PowerShell Module by Doug Finke from PowerShellGallery is a very popular and much helpful module, it works even without Excel installed on your computer, and again it’s an open source project in GitHub. This module is very rich in features and compact to use in your code, and I find this module is very useful and helpful.

Now let’s get started with ImportModule module in PowerShell Core

SincePowerShellGalleryis a default repository in PowerShell, you don’t need to set the repository again, just ensure that you havePSGalleryas a default repository…


Now it’s time to get the module installed and imported to the session…

# Find the module
Find-Module -Name ImportModule

# Install the modules
Find-Module -Name ImportModule | Install-Module 
Install-Module -Name Install-Module

# Update the module
Update-Module -Name ImportExcel

# Verify the module is installed
Get-Module -Name ImportExcel -ListAvailable

# Import the module
Import-Module -Name ImportExcel


To check the CmdLets available in the ImportExcel module, run the CmdLet below…

Get-Command -Module ImportExcel

Now let’s see how to export the data to excel and various options…

Export-Excel CmdLet will do all the magic with various parameters; to simply export the data to excel, just pipe the output to Export-Excel, this will export the data to excel, apply filters, auto size the columns and pop up the excel window, but this will not save the file to disk.

Get-Service | Select Name, DisplayName, Status | Export-Excel


… just to export the data to excel and save the file to disk, use -Path flag with Export-Excel …

Get-Service | Select Name, DisplayName, Status | Export-Excel -Path C:\Test.xlsx


Observe the data in the excel opened after the file was created, where the columns are compact, not readable and no filters applied. By default without any parameters Export-ExcelCmdLet will not save the file to disk, show the window, apply filters, auto size the columns, but if we use -Path and want to pop up the window, apply filters and auto size the columns we need to use the -Show, -AutoSize, -AutoFilter flags…

# To Show the window after the file save to disk
Get-Service | Select Name, DisplayName, Status | Export-Excel -Path .\Test.xlsx -Show

# To apply filters, and allow autosize the columns
Get-Service | Select Name, DisplayName, Status | Export-Excel -Path .\Test.xlsx -Show -AutoSize -AutoFilter

Now let’s see formating the text in the excel reports…

# Get the services exported to excel and highlight the services state seperately for services running and services are stopped.
$ConTxt1 = New-ConditionalText -Text 'Stopped' -ConditionalTextColor Red -BackgroundColor Yellow
$ConTxt2 = New-ConditionalText -Text 'Running' -ConditionalTextColor Yellow -BackgroundColor Green
Get-Service | Select Status, Name, DisplayName | Export-Excel -Path .\Test.xlsx -AutoSize -Show -ConditionalFormat $ConTxt1, $ConTxt2
# '-ConditionalFormat' parameter accepts arrays

import-excel-6Setting the icons to the values to represent the changes with in the given range…

# Get the processes, and represent the changes in the memory with the icons
$ConFmt = New-ConditionalFormattingIconSet -Range "C:C" -ConditionalFormat FiveIconSet -IconType Arrows
Get-Process | Select Company, Name, PM, Handles | Export-Excel -Path .\Process.xlsx -Show -AutoSize -AutoFilter -ConditionalFormat $ConFmt

# Also club it with the conditional text
$ConTxt = New-ConditionalText -Text 'Microsoft' -ConditionalTextColor Yellow -BackgroundColor Green
Get-Process | Select Company, Name, PM, Handles | Export-Excel -Path .\Process.xlsx -Show -AutoSize -AutoFilter -ConditionalFormat $ConFmt, $ConTxt


Now let’s see some creating pivot tables and charts…

# Get the services and identify the number of service are running & stopped and the services count per start type
$Data = Get-Service | Select-Object Status, Name, DisplayName, StartType | Sort-Object StartType

# Parmaters in a hashtable
$Param = @{
Show = $true
AutoSize = $true
IncludePivotTable = $true
PivotRows = 'StartType' 
PivotData = 'StartType' 
PivotColumns = 'Status'

# Create the pivot table
$Data | Export-Excel -Path C:\GitRepo\Test.xlsx @Param


# Get the services and identify the number of service are running & stopped and the services count per start type
$Data = Get-Service | Select-Object Status, Name, DisplayName, StartType | Sort-Object StartType

# Parmaters in a hashtable
$Param = @{
Show = $true
AutoSize = $true
PivotRows = 'StartType' 
PivotData = 'StartType'
IncludePivotChart = $true
ChartType = 'PieExploded3D'

# Create the pivot charts
$Data | Export-Excel -Path C:\GitRepo\Test.xlsx @Param


There are plenty of options are available, so please explore the all the features in the ImportExcel and make the best use of this module. You can also achive the same by writting your own code, but this is very compact and easy to use.

Many thanks to Doug Finke! #ImportExcel


‘Clear-RecycleBin’ is not recognized as the name of a cmdlet in PowerShell Core

Recently I have upgraded to PowerShell Core and slowly switching from Windows PowerShell to PowerShell Core. I have noticed quite a few CmdLets are missing in the PowerShell Core, since it became an open source and supports on cross-platform most of the platform dependent CmdLets won’t work on the other platforms. I usually clear my temp folders and recyclebin in all my computers frequently, and noticed Clear-RecycleBin CmdLet is not a valid CmdLet in PowerShell Core…

Clear-RecycleBin : The term 'Clear-RecycleBin' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Clear-RecycleBin -Force
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Clear-RecycleBin:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

So I have decided to create a PowerShell function to achieve almost the the same functionality of Clear-RecycleBin using .NET class, and here is the function…



Note: I have not added the -DriveLetter flag, since I want to clear the recyclebin from all the drives, if you want clear the recyclebin from a specific drive, you need add the driveLetter argument to the Empty method in the C# code and add the -DriveLetter parameter to the PowerShell function.

Thank you.

Just a tip #4 – Download a zip file from the internet and extract using PowerShell.

The code below will download the .zip file from the internet, then extracts the files from the zip and opens the extracted folder…

$Url = 'https://download.sysinternals.com/files/BGInfo.zip'
$ZipFile = 'C:\ZipFolder\' + $(Split-Path -Path $Url -Leaf)
$Destination= 'C:\Extracted\'

Invoke-WebRequest -Uri $Url -OutFile $ZipFile

$ExtractShell = New-Object -ComObject Shell.Application
$Files = $ExtractShell.Namespace($ZipFile).Items()
Start-Process $Destination