How to Extract Directory from File Path in PowerShell? [3 Methods]

Extract Directory from File Path in PowerShell

Sometimes, you might need to extract the directory from the file path. In this PowerShell tutorial, I will explain how to extract a directory from a file path in PowerShell using various methods. To get the directory from a file path in PowerShell, you can use the Split-Path cmdlet with the -Parent parameter. For example, … Read more

How to Get the Size of a File in PowerShell?

How to Get the Size of a File in PowerShell

Recently, one of my clients asked to get the size of files in a folder. So, I wrote a PowerShell script to get the file size. In this PowerShell tutorial, I will explain how to get the size of a file in PowerShell. To get the size of a file in PowerShell, you can use … Read more

How to Check if a File Contains a String in PowerShell?

Check if a File Contains a String in PowerShell

While working with files in PowerShell, you may get requirements to check if a file contains a specified string. PowerShell provides different methods to check if a file contains a string. Let us check each method with examples. To check if a file contains a specific string in PowerShell, you can use the Select-String cmdlet … Read more

How to Write JSON to File in PowerShell?

How to Write JSON to File in PowerShell

In this PowerShell tutorial, I will explain how to write JSON to a file in PowerShell. To write JSON to a file in PowerShell, you can use the ConvertTo-Json cmdlet to convert a PowerShell object into a JSON string, and then output this string to a file using Out-File or Set-Content. For example: This approach is simple and effective for … Read more

How to Delete a File in PowerShell? [3 Methods]

Delete Multiple Files in PowerShell

Do you want to delete files in PowerShell? In this tutorial, I will show you various methods to delete files using PowerShell. To delete a file in PowerShell, use the Remove-Item cmdlet followed by the -Path parameter and the file path. For instance, Remove-Item -Path “C:\path\to\file.txt” will remove the specified file. If you need to … Read more

How to Copy and Rename Files in PowerShell?

Copy and Rename Files in PowerShell

In this article, I will explain various methods to copy and rename files using PowerShell, providing examples and complete scripts to help you understand better. To copy and rename a file in PowerShell, you can use a combination of the Copy-Item and Rename-Item cmdlets. First, use Copy-Item to copy the file to the desired location, … Read more

PowerShell Foreach File in Folder

PowerShell Foreach File in Folder

Do you want to iterate files in a folder using PowerShell? In this PowerShell tutorial, I will explain everything about the PowerShell Foreach file in a folder. To iterate through each file in a folder using PowerShell, you can use the Get-ChildItem cmdlet to retrieve the files and then loop through them with a foreach … Read more

How to Count Lines in a File in PowerShell?

How to Count Lines in a File in PowerShell

Recently only, while working on a file system requirement in PowerShell, I was required to count number of lines presented in a file using PowerShell. I tried different methods. In this PowerShell tutorial, we’ll explore various methods to count lines in a file using PowerShell with examples. To count lines in a file using PowerShell, … Read more

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.