Author: Arpit Mandliya
- 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-676b699b9157b357014912/] 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-676b699b91642033668858/] [crayon-676b699b91645996777875/] 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-676b699b91737474990908/] [crayon-676b699b9173a078610918/] 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-676b699b9197b397078216/] 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-676b699b91aa0013170289/] [crayon-676b699b91aa3357608331/] 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-676b699b91bea203464709/] [crayon-676b699b91bed383849239/] 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-676b699b91dd6320966322/] [crayon-676b699b91dd9008679763/] 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 […]
- 05 January
PowerShell – Multiline Comment
Using <# #> Tags Use the <# tag at the beginning of comments and the #> tag at the end of comments to create multiline comments in PowerShell scripts. All lines inside the comment block are part of the comments. [crayon-676b699b91fbc532244716/] In programming, we use a comment block to provide explanations or details about the […]