• 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. [crayon-6606593f85974192216154/] [crayon-6606593f8597f098208824/] The above code returned PowerShell is running as admin if the PowerShell is running as an administrator; otherwise, it returned PowerShell is not running as admin. Let’s break down the code to understand it. […]

  • 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. [crayon-6606593f8895d448830447/] [crayon-6606593f88969060096367/] First, we declared and initialized a variable called $software having a software’s complete name that we wanted to check. Next, we used the Get-Package cmdlet to retrieve a list of all packages installed on […]

  • 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 […]

  • 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. [crayon-6606593f8cf4e762629323/] [crayon-6606593f8cf56280583472/] In the above code, the Test-Connection cmdlet sends an ICMP echo request to the hostname. First, the code sets […]

  • 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 […]

  • Format number to 2 decimal places in PowerShell
    16 April

    Format Number to 2 Decimal Places in PowerShell

    In PowerShell, there are so many methods to round or format the numbers to two decimal points. In the following methods, the following steps will be followed: Initialize a variable with the floating point number Round or format the number using the specific method Display the Rounded or formatted number on the screen Using ToString() […]

  • PowerShell get ad user account expiration date
    15 April

    PowerShell Get Ad User Account Expiration Date

    Using Get-AdUser Cmdlet with Select-object cmtlet Use the Get-AdUser with Select-object to get the ad user account expiration date in PowerShell. [crayon-6606593f979d8980461246/] [crayon-6606593f979e2382725351/] Here, the PowerShell cmdlet Get-ADUser was used to retrieve the information about the users of the Active Directory as it is a centralized system. Now, what is Active Directory? Microsoft provides directory […]

  • Powershell convert word to PDF
    14 April

    PowerShell Convert Word to PDF

    Using Microsoft Word COM Object To convert the given Microsoft Word document to PDF: Create a COM object using the New-Object cmdlet. Use the Open() method to open the MS Word file. Use the SaveAs() method to save the PDF file. Use the Close() method to close the Word document. Use the Quit() method to […]