Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Blog posts : "Powershell"

Converting CSV String Values to Boolean in PowerShell

While working with CSV file I had few column in the true and false boolean value. But when I was importing csv file in PowerShell it was treating them as a string value instead of boolean in the output. Here I will explore how to convert true and false values to boolean.

Powershell convert string to boolean System.convert to boolean method csv file parse boolean doller.png

Method 1

To safely…

Read more

Navigating Nested Loops in PowerShell A Guide to Loop Labels

At first glance, as in the below shared PowerShell script looks like a simple set of nested foreach loops printing numbers. But it has very powerful - and always overlooked - control structure: called Loop Label.

:OuterLoop foreach ($OuterNumber in 1..4)
{    
    Write-Host "== Starting Oute…

Read more

How to Capture PowerShell Trace and Debug Messages in DebugView

When you’re running PowerShell scripts as scheduled tasks, background jobs, Runspace jobs, or on remote servers, normal Write-Host or Write-Debug output often disappears. That’s where System.Diagnostics.Trace comes in.

System.Diagnostics.Trace is a built-in.NET class designed to instrument, monit…

Read more

How to Get Installed Software Features List Using PowerShell WMI-CIM

While working with VMware Tools, I needed to audit exactly which features/components were installed on a VM. VMware Tools isn’t just one package — it installs several sub-features like drivers, services, and utilities. I wanted a clean report showing each component and whether it was actually instal…

Read more

PowerShell Pro Tip: How to Overwrite and Update the Same Line ProgressBar

When writing long-running PowerShell scripts, displaying real-time feedback keeps users engaged and reassures them that the script hasn't frozen. However, flooding the console with hundreds of lines of text makes it unreadable, and using Clear-Host causes an annoying screen flicker.

The ideal sol…

Read more

How to Audit HPE iLO Active Directory Settings with PowerShell and Redfish API

This script focuses on automating the audit of Active Directory and LDAP settings across multiple generations of HPE iLO using PowerShell and the Redfish API. Before running the script First you will need to create a CSV file with HPE Generation, IP, username and password information as shown in the…

Read more

Automating Windows VM Cloning and sysprep on Nutanix with PowerShell

One of my friend asked for a PowerShell script for Nutanix Windows virtual machine cloning and configuration. This PowerShell script automates the process of cloning virtual machines and joining them to a domain. It uses the Nutanix PowerShell module to interact with the Nutanix cluster and clone vi…

Read more

Parallel Ping and Port Testing in PowerShell Using Runspaces

In this article, I demonstrate how to test network connectivity for a list of computer names or IP addresses using PowerShell. Each target system is tested for ICMP reachability (ping) and TCP connectivity on port 445, which is commonly used for SMB.

The core logic is implemented in a custom func…

Read more

Get PowerShell Cmdlet Parameter Enum Values Easily

Enumeration is the action of mentioning a number of things one by one, often to count them or describe them but it has specific meanings in computer science, data types like enum for named constants. 

In the PowerShell to list the enumeration information for a parameter, you will need to use elem…

Read more

Automating Linux VM Cloning and IP Configuration on Nutanix with PowerShell

This simple PowerShell script clones Nutanix Linux virtual machines. To use this script, first download and install the PowerShell cmdlets from Nutanix Prism Central. You can find the installed plugin folder under C:\Program Files(x86)\Nutanix folder. From there you can load plugins.

A screenshot of the Nutanix Prism Central web interface dropdown menu under the help icon. The menu highlights options for 'Download Cmdlets' and 'Download nCLI' in a red box, along with links for Update Profile, REST API Explorer powershell, and Sign Out.

After in…

Read more

PowerShell File Renaming: How to Reorder Files Sequentially Using a CSV Map

I recently received a task to rename a bunch of files by changing their numbering in the filename while working on a PowerShell DevOps project. I had multiple Markdown files with numbers at the start of their names, and I needed to change these numbers with the filename based on a mentioned in CSV f…

Read more

High-Performance Network Auditing: Custom Ping and TCP Port Testing in PowerShell .Net Objects

This article dives into the Test-TcpPort function, a compact script that resolves hostnames to IPs, pings for basic reachability, and tests port connectivity with a timeout. I will break down its mechanics in short. At its core, Test-TcpPort leverages .NET's System.Net and System.Net.Sockets namespa…

Read more

Building a Unified Ping and Port Connectivity Report with PowerShell

In this article, I will explore two PowerShell scripts that test network connectivity (Ping) and port availability (Port Query) on multiple computers. I will discuss the scripts, their differences, and how to use them effectively. First Script is used for Synchronous Network Testing. The first scrip…

Read more

PowerShell PSRemoting Fix: Bypassing "Access is Denied" for Privileged Admin Commands

While working with PowerShell Remoting (PSRemoting), I was able to successfully connect to a remote machine using Enter-PSSession, but any administrative command—such as resetting the local Administrator password—failed with:

System error 5 has occurred.
Access is denied.

Even though the …

Read more

PowerShell Remoting Access is Denied: How to Fix PSRemoting for Administrators Group Accounts

After successfully configuring Microsoft PowerShell PSRemoting, I was able to login with local Administrator user without any issue. But after creating another user, adding it to Administrators group then logging with it was throwing error message of Access is denied.

Screenshot of PowerShell showing the Enter-PSSession failure with the error message: 'Access is denied' for a local administrator account (vmadmin) trying to connect to a remote server 10.0.0.4 local administrators.

PS VM02 > Enter-PSSess…

Read more

Bypass the Domain Wall: How to Enable PSRemoting WinRM in a Workgroup Environment

This is very simple and easy instructions to configure PowerShell PSRemoting WinRM on Windows system which is not joined into domain (Basically they are in workgroup). On the the first system login and and open PowerShell as administrator and Run below commands to configure PowerShell Remoting. 

Read more

Broadcom PowerCLI: Building a GUI to Check VMware HA Admission Control Compliance

This PowerCLI GUI script I have written to audit VMware ESXi clusters high availability (HA) inside vCenter Server. This script validates below ideal configuration is defined on the cluster and tells me whether configuration is correct with green tick and non-compliant with red cross.

Note: This …

Read more

The PowerShell Sorting Trap: Why 10 Always Comes Before 2 in Your CSV Data

When sorting CSV data with PowerShell, I observed unexpected results, as shown in the screenshot below. The initial command, Import-Csv C:\Temp\Numberings.csv, shows that the numbers in the CSV are out of sequence. To sort these numbers, I used the simple pipeline command Sort-Object specifying the

Read more

Terraform String Encoding and Decoding with PowerShell

This is another script I have written to encode and decode string for Terraform using PowerShell GUI. These scripts helps me in the live demonstrations and PowerPoint to client about infrastructure as a code. Once script is executed in PowerShell GUI, it looks like below, It helps to Base64 Encode g…

Read more

Self-Signed Certificates Made Easy with PowerShell GUI

I was delivering few demos for Azure Application Gateway client side, I got information, there will be very limited Internet and only specific things will work in the given environment. In one of the demo I wanted to created few Self Signed SSL Certificates for Azure Application Gateway. In the demo…

Read more

20 blog posts

Blog Search

Page Views

1 5 3 5 4 2 9 2

Archive

Follow me on Blogarama