Author: Arpit Mandliya
- 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-68bb99e312aaf933937511/] [crayon-68bb99e312ab7859091452/] 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 […]
- 13 January
Merge Multiple CSV Files in PowerShell
Using Import-Csv and Export-Csv Before merging multiple .csv files, let’s write a script to see how many .csv files are in the specified directory. For that, create a variable called $sourcefiles containing a list of all the CSV files in the directory. Next, use the Get-ChildItem cmdlet to retrieve all the CSV files in the […]
- 10 January
PowerShell – Multiline Command
Using Backticks Use backticks to split multiline commands in PowerShell. [crayon-68bb99e3141b8385616856/] Usually, we get an automatic line continuation in PowerShell when the command can’t syntactically be complete. However, if splitting a multiline command is required, then using backticks is preferred in such scenarios as presented above where too many operators are not involved; otherwise, it […]
- 08 January
PowerShell – Call Function with Parameters
Using Positional Parameters To call a function, use positional parameters separated by space. Please note that you need to pass parameters in sequence while calling the function. [crayon-68bb99e3142cc008235522/] [crayon-68bb99e3142cf782738498/] Microsoft’s PowerShell consists of a command-line shell and scripting language. It is based on the .NET framework for task automation and configuration management and helps power […]
- 08 January
Press Any Key to Continue in PowerShell
Solutions for PowerShell Integrated Scripting Environment(ISE) and Command Line Console Using Read-Host Cmdlet Use the Read-Host command to enable press any key to continue in PowerShell. [crayon-68bb99e3143e8664523230/] [crayon-68bb99e3143eb007028023/] The Read-Host cmdlet is the most commonly used and easy to understand. We used it to pause execution and prompt the user to get the input line […]
- 08 January
PowerShell – Unzip File
Using Expand-Archive Cmdlet Use the Expand-Achrive cmdlet to unzip a file/folder in PowerShell. [crayon-68bb99e314603374770933/] Please note that Expand-Archive cmdlet is available from PowerShell 5 onwards. Print envionment variable $PSVersionTable.PSVersion to check version of your PowerShell. We used the Expand-Achrive cmdlet to unzip a folder from the given location and save the unzipped folder in the […]
- 07 January
PowerShell – Write to Log File
Using the Transcript To write to a log file using Transcript: Use the Start-Transcript cmdlet to start writing to the log file. Perform operations normally without writing anything to the file. Use the Stop-Transcript to stop the transcript. [crayon-68bb99e314749808840899/] [crayon-68bb99e31474c742178646/] A Transcript is a saved record of all the commands and output that a PowerShell […]
- 07 January
PowerShell – Get Size of Folder
Using Get-ChildItem with Measure-Object Use Get-ChildItem with the Measure-Object cmdlet to get the size of files in the specified directory. [crayon-68bb99e3148b7394161207/] [crayon-68bb99e3148ba282128672/] Please note that above sum doesn’t include subfolder sizes. If you want to include subfolder as well, header over to this section. The Measure-Object cmdlet was used to calculate the property values of […]
- 07 January
PowerShell – Read File Line by Line
Using Get-Content Cmdlet Use the Get-Content cmdlet to read file line by line in PowerShell. [crayon-68bb99e314a8b382585429/] [crayon-68bb99e314a8e388707580/] We used the Get-Content cmdlet to read the specified file line by line in PowerShell. It is used to get the content or data of the specified item; here, the specified item can be a text file or […]