Windows

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… Function Get-WinSrvFromInv { <# The purpose of this function is to retrieve the list of servers for which you want to check the Windows Activation status. Write your piece of code to retrieve the servers from your inventory. for example, Get-Content -Path $InvPath\Server.txt #> return @("Srv2K19", "Srv2K16", "Srv2K12") } Function Get-WindowsActivation { <# This is a PowerShell advanced function to retrieve the Windows Activation Status using CIM classes. It takes one or more servers as an input, and it accepts through pipeline as well This script will check the connectivity, and then checks the activation status It collects the info from all the servers and then return the value of error at once. #> [CmdLetBinding()] Param ( [Parameter(Mandatory=$true,ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string[]] $ComputerName ) Begin { $ActivationStatus = @() } Process { foreach ($CN in $ComputerName) { $PingStatus = Test-Connection -ComputerName $CN -ErrorAction Stop -Count 1 -Quiet $SPL = Get-CimInstance -ClassName SoftwareLicensingProduct -ComputerName $CN -Filter "PartialProductKey IS NOT NULL" -ErrorAction Stop $WinProduct = $SPL | Where-Object Name -like "Windows*" $Status = if ($WinProduct.LicenseStatus -eq 1) { "Activated" } else { "Not Activated" } if ($PingStatus -ne $true) { $PingStatus = "No" $Status = "Error" } else { $PingStatus = "Yes" } $ActivationStatus += New-Object -TypeName psobject -Property @{ ComputerName = $CN Status = $Status IsPinging = $PingStatus } } } End { return $($ActivationStatus | Select-Object -Property ComputerName, IsPinging, Status) } } ## Invoke the functions. Get-WinSrvFromInv | Get-WindowsActivation And you will get the status as below…


3 September 2019

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 + v 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 or {}.id. 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. 


30 August 2019