Author: Arpit Mandliya
- 26 January
Create File If Not Exists in PowerShell
Using the if-else Statement We can use the if-else statement to create a file as follows: Use the New-Item Cmdlet To create a file if it does not exist in PowerShell: Use the Test-Path cmdlet with the if condition to check if the file exists. Use the New-Item cmdlet to create a new file if […]
- 26 January
Check if Folder Exists in PowerShell
Using Built-in Cmdlets and Methods We can use built-in cmdlets and methods to check if a directory exists. Use the Test-Path Cmdlet To check if a folder exists, use the Test-Path cmdlet. [crayon-676b68cfb07b0049417597/] [crayon-676b68cfb07b4365777169/] PowerShell’s Test-Path cmdlet verifies that a path exists, regardless of whether it is a file or folder. This cmdlet helps write […]
- 23 January
Convert Month Number to Name in PowerShell
Using the Get-Culture() Cmdlet We can use the Get-Culture cmdlet in the following three possible ways: To Convert the Hardcoded Month Number to the Name To Convert the Month Number from a Date to the Name To Convert the Current Month Number to the Name Let’s learn the above-mentioned approaches one by one below. Convert […]
- 23 January
Delete Empty Folders in PowerShell
There are multiple ways that we can use to delete the empty folders in PowerShell but before going into the details, let’s have a look at the following directory structure to know how many and which folders are empty. [crayon-676b68cfb0a88333115963/] Now, let’s dive into the possible solutions to delete empty folders. Using the Remove-Item with […]
- 23 January
PowerShell – Where-Object with Multiple Conditions
Using Where-Object Cmdlet with Multiple Conditions In PowerShell, we have various comparison and logical operators that we can use with the Where-Object cmdlet to apply multiple conditions. Let’s explore a few scenarios below. [crayon-676b68cfb0bad120881053/] [crayon-676b68cfb0bb1100308405/] The above command returned an item where the extension of the selected item is .txt, and its length is equal […]
- 18 January
Rename Files with PowerShell
Rename Single File with PowerShell Using Rename-Item with/without the -Path Parameter Use the Rename-Item cmdlet to rename a file in PowerShell. [crayon-676b68cfb0d15094596523/] We used the Rename-Item cmdlet to rename the test.txt file to the newtest.txt file. Note that this command will look for the file in the current directory. If you want to search for […]
- 18 January
PowerShell – Redirect Output to File
Using Out-File Cmdlet Use the Out-File cmdlet to redirect PowerShell output to a file. [crayon-676b68cfb0e2b648758275/] The Get-Process is used to retrieve all the processes that are currently running on our machine (local computer). We can filter this information by specifying parameters; for instance, we used the -Name parameter to get all chrome processes currently running. […]
- 18 January
PowerShell – Logical Operators
Using Logical Operators in PowerShell PowerShell’s logical operator is a potent tool for comparing data and carrying out operations depending on those comparisons. It allows the user to design an if-then scenario in which several parameters are compared. In other words, it enables the users to make choices following the criteria they specify. A logical […]
- 13 January
Show Hidden Files (dotfiles) with Windows PowerShell
Using Get-ChildItem with the -Force Parameter To show hidden files with other files, use the Get-ChildItem cmdlet with the -Force or -fo parameter. [crayon-676b68cfb1077084908708/] [crayon-676b68cfb1079093570600/] The Get-ChildItem is a PowerShell cmdlet that lists the items in a specified location. By default, it lists the files and directories in the current directory, but we can use […]