Posts tagged: PowerShell

Long PowerShell statements

By , 11 august, 2008 20:36

PowerShell statements can be large, and it’s not always practial to enter it on a single line in the console or in a script. In PowerShell, as wel as in most other programming lanuages or consoles it is posible to write statements over several lines.

When the console determines a line is incomplete, powershell continues to the next line processing the statement. For example, where the first line in a statement ends with the pipe operator, as in:

Long statement example:

18# Get-Process | Where {$_.ProcessName -eq ‘msiexec’} | Format-table ID, CPU, Name
Id CPU Name
– — —-
4808 0,046875 msiexec

Same statemen over three lines:

19# Get-Process |
>> Where {$_.ProcessName -eq ‘msiexec’} |
>> Format-table ID, CPU, Name
>>
Id CPU Name
– — —-
4808 0,046875 msiexec

In a PS1 script you can use the ` tag:

$excel = New-Object -comobject `
excel.application

Post to Twitter Post to Facebook Post to LinkedIn

Panorama Theme by Themocracy