![]() These commands are executed in sequence, print message and get file version and print output as below In the above PowerShell multiple commands example, it has 3 commands separated by semicolon ( ) Let’s consider an example below to run multiple commands in one line Write-Host "Get File version" $fileversion =(Get-Command D:\PowerShell\ShellWatcher.dll).FileVersionInfo.FileVersion Write-Host "File version -" $fileversion To execute multiline command in one line in PowerShell, use a semicolon ( ) after each command. In the above PowerShell multiline command example, PowerShell ‘s ` backtick character splits long command over multiline command and uses multiline comment out code. We can easily split long commands into multiple lines using ` (PowerShell backtick character) for a line break in the following command Get-CimInstance -ComputerName localhost win32_logicaldisk | where caption -eq "C:" | foreach-object ' ` Let’s consider an example, we want to get free disk space on a local computer name is a long command which makes it very difficult to read and manage. To split long command into multiple lines, use the backtick (`) character in the command where you want to split it into multiple lines. 5 Conclusion PowerShell Multiline Command
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |