• PowerShell check if module is installed
    22 April

    PowerShell Check if Module is Installed

    Using Get-Module Cmdlet Use Get-Module with -Name parameter to check if a module is installed in PowerShell. Get-Module -ListAvailable -Name ImportExcel Directory: C:\Users\user\Documents\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 7.8.4 ImportExcel {Add-ConditionalFormatting, Add-ExcelChart, Add-ExcelDataV... The Get-Module retrieves information about loaded modules and available modules that can be imported. The -ListAvailable parameter filters […]

  • PowerShell check if directory is empty
    21 April

    PowerShell Check if Directory is Empty

    For this article, we are using three directories, E:\Test\Script Files, E:\Test\Test Files, and E:\Test\Sample Files. The E:\Test\Script Files directory is not empty and contains test.bat and testPS.ps1 files, while the E:\Test\Test Files directory is empty because it contains nothing, neither files nor folders The E:\Test\Sample Files directory is also not empty; it contains file.txt, file1.txt, […]

  • Check if PowerShell is running as admin
    21 April

    Check if PowerShell is Running as Admin

    Using WindowsPrincipal and WindowsIdentity Classes Use the WindowsPrincipal and WindowsIdentity Classes to check if PowerShell runs as an admin. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() ) $isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if ($isAdmin) { Write-Host "PowerShell is running as admin." } else { Write-Host "PowerShell is not running as admin." } PowerShell is running as admin. The above […]

  • PowerShell check if software is installed
    18 April

    PowerShell Check If Software Is Installed

    Using Get-Package with Select-Object Cmdlet Use Get-Package with the Select-Object cmdlet to check if the specified software is installed. $software = "Java(TM) SE Development Kit 18.0.2.1 (64-bit)" Get-Package | Where-Object { $_.Name -eq $software } | Select-Object Name, Version Java(TM) SE Development Kit 18.0.2.1 (64-bit) First, we declared and initialized a variable called $software having […]

  • Convert Array to ArrayList in PowerShell
    16 April

    Convert Array to ArrayList in PowerShell

    One of the everyday tasks is converting an array to an ArrayList in PowerShell. It can be helpful when you need to work with dynamic data structures or manipulate data in memory. However, before we dive into how to convert an array to ArrayList, it’s essential to understand the difference between these two. An array […]

  • Bash split string and get last element
    16 April

    Bash Split String and Get Last Element

    Using read Command Use the read command with parameter expansion to split the string and get the last element in Bash. #!/bin/bash myString="Hello:World:How:are:you?" read lastElement <<< "${myString##*:}" echo "The last element is: $lastElement" The last element is: you? In the above example, the read command is used with the ${myString##*:} parameter expansion to get the […]

  • PowerShell check if URL is reachable
    16 April

    Check if URL is Reachable in PowerShell

    Using Test-Connection Cmdlet To check if URL is reachable in PowerShell: Convert url to System.url object and get host property using Select-Object cmdlet. Use Test-Connection cmd to check if host is reachable or not. $url = "https://www.google.com" $hostname = [System.Uri]$url | Select-Object -ExpandProperty Host $isReachable = Test-Connection -ComputerName $hostname -Quiet if ($isReachable) { Write-Host "$url […]

  • PowerShell get number from String
    16 April

    Get Number from String in PowerShell

    1. Introduction PowerShell, a versatile scripting language used primarily on Windows, often requires the extraction of numbers from strings for data processing and manipulation. For example, given a string Order1234, the goal is to extract the number 1234 from it. The expected output, in this case, is a numerical value (integer or float) extracted from […]

  • Convert String to byte array in PowerShell
    16 April

    Convert String to Byte Array in PowerShell

    Using System.Text.Encoding Class The System.Text.Encoding class converts the specified string to a byte array in PowerShell. This class can use a particular, default, or custom encoding format. Let’s see how we can use them. Use System.Text.Encoding Class with a Particular Encoding Use the System.Text.Encoding class with specific encoding to convert a string to byte array […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.