• Powershell convert Guid to String
    14 April

    PowerShell Convert Guid to String

    💡TL;DR Use the ToString() method on System.Guid to convert a GUID to a string in PowerShell. [crayon-67691e10b7a72197942532/] [crayon-67691e10b7a79037683906/] Before diving into the solutions, let’s understand what GUID is. In PowerShell, a Globally Unique Identifier (GUID) is a 128-bit identifier used to identify objects uniquely—for instance, folders, files, registry keys, and other system resources. Remember, GUIDs […]

  • Generate random String in PowerShell
    10 April

    Generate Random String in PowerShell

    Using [System.Guid] Class To generate a random string in PowerShell: Create a globally unique identifier using the NewGuid() method. Use the ToString() method to transform the GUID (created in the previous step) to String format. Use the Write-Host cmdlet to print the random string. [crayon-67691e10b8660549995811/] [crayon-67691e10b8665751568715/] The New-Guid() is a static method of [System.Guid] class […]

  • Mandatory Parameters in PowerShell
    10 April

    Mandatory Parameters in PowerShell

    Using Mandatory Attribute Use the Mandatory attribute to make parameters mandatory in PowerShell. [crayon-67691e10b888b712343827/] [crayon-67691e10b888e816190689/] First, we defined a function named DisplayName preceded by the function keyword. Inside this function, we used the param keyword (also referred to as param() block), which was used to define the $Name parameter; this parameter was of the string […]

  • Get yesterday's date in PowerShell
    09 April

    Get Yesterday’s Date in PowerShell

    Using Get-Date Command with AddDays() method Use the Get -Date command with AddDays() method to get yesterday’s date in PowerShell. Pass -1 to AddDays() to substract one day from current date and time [crayon-67691e10b8b04353771296/] [crayon-67691e10b8b07340353011/] The simplest way to get yesterday’s date in PowerShell is by using the Get-Date cmdlet with AddDays() method. For example, […]

  • TypeError - dict_values is not subscriptable
    09 April

    TypeError: ‘dict_values’ Object Is Not Subscriptable

    Reproducing TypeError: ‘dict_values object is not subscriptable When you try to access the dict_values object through index, the error will raise stating TypeError: 'dict_values' object is not subscriptable. Here is the example below. [crayon-67691e10b8bea371189713/] [crayon-67691e10b8bec952325343/] Convert dict_values object to list To resolve TypeError: 'dict_values object is not subscriptable, convert dict_values object to list before accessing […]

  • Get all files in directory reclusively in PowerShell
    09 April

    Get All Files in Directory Recursively in PowerShell

    In PowerShell, the directory can be retrieved recursively using the Get-ChildItem cmdlet and the -Recurse parameter. [crayon-67691e10b8cfe995064354/] [crayon-67691e10b8d01730768752/] If you are looking to get all files in current directory in PowerShell, you can use below command: [crayon-67691e10b8d02871567402/] The folders and files can also be excluded using the -Exclude parameter. First, have a look at the […]

  • Get Full path of file in PowerShell
    07 April

    PowerShell- Get Full Path of File

    Get Full Path of File in PowerShell To get full path of file in powershell: Go to folder where file is present. You can go to any parent folder as well. Use Get-ChildItem with -Recurse option. Pipe it to where-object cmdlet to filter filename. In this example, we have given filename as test.ps1 Pipe it […]

  • PowerShell - get Permissions on folder and subfolders
    07 April

    PowerShell – Get Permissions on Folder and Subfolders

    To understand how to get permissions on a folder and subfolder in PowerShell, you must first understand what folder and subfolder permissions are. A folder’s permissions establish who can access and modify files and folders. A subfolder permission is a permission set for a folder containing other folders. In general, permissions set on a folder […]

  • Split Path into Array in PowerShell
    05 April

    PowerShell Split Path into Array

    Split Path into Array in PowerShell Using Split() Method Use the Split() method to split the path into an array in PowerShell. [crayon-67691e10b98f1607294715/] [crayon-67691e10b98f4281459155/] First, we defined a $path variable and set its value to a path as demonstrated above; you can initialize it with your own path. Next, we chained the Split() method with […]