PowerShell Script source output to file best written _powershell

Source: Internet
Author: User

I used to put a script fragment in a string, a multiline string called here-string, such as:

Copy Code code as follows:
$code =@ "
Invoke-webrequest
Get-service-name Adobearmservice
"@

Disadvantages have two:

If I am this $code string is very long, the execution error, I want to be wrong, but because it is a string, in the ISE can not be highlighted, inconvenient. So, I guess I'll have to take the script out of this string and put it in another Ise window to make a careful identification.
The string in the $code defines some variables, and I don't want these variables to be automatically parsed into values. Then I'm going to have to get out of the box. Single quotes, if the string contains just a large number of single quotes, the estimated inverted quotation marks (escape characters) are flooded.
Today it is not the fighter of the hen, but the Tchaikovsky in the hen: the Magic brace.

Copy Code code as follows:

{
Invoke-webrequest ' Http://www.jb51.net '
Get-service-name Adobearmservice
$name = ' Mosser Lee '
} | Out-file ' My.ps1 '

The above script can be highlighted in Ise, and after execution, the source script in curly braces is clean and authentic and is saved to the script file.

Article Source: http://www.pstips.net/output-source-scripts-to-file.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.