Author: Arpit Mandliya
- 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-67bb86c515ea3232307338/] [crayon-67bb86c515ea9889755935/] 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 […]
- 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-67bb86c5161f8859511060/] [crayon-67bb86c5161fc582908893/] The New-Guid() is a static method of [System.Guid] class […]
- 10 April
Mandatory Parameters in PowerShell
Using Mandatory Attribute Use the Mandatory attribute to make parameters mandatory in PowerShell. [crayon-67bb86c516406648673675/] [crayon-67bb86c516409705953618/] 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 […]
- 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-67bb86c516718201008846/] [crayon-67bb86c51671c302998038/] The simplest way to get yesterday’s date in PowerShell is by using the Get-Date cmdlet with AddDays() method. For example, […]
- 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-67bb86c516805300975663/] [crayon-67bb86c516808132292449/] Convert dict_values object to list To resolve TypeError: 'dict_values object is not subscriptable, convert dict_values object to list before accessing […]
- 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-67bb86c51690c742927621/] [crayon-67bb86c51690f178806627/] If you are looking to get all files in current directory in PowerShell, you can use below command: [crayon-67bb86c516910935186438/] The folders and files can also be excluded using the -Exclude parameter. First, have a look at the […]
- 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 […]
- 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 […]
- 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-67bb86c516da2977885243/] [crayon-67bb86c516da5628429385/] 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 […]