Shielding output results of PowerShell tips _powershell

Source: Internet
Author: User

After any results returned from the PS command, it is important to shield them for any unimportant result.

There are a number of ways to implement it, and here are two more specific methods. Note the following two lines try to create a new folder in C disk:. New-item will output the object of this folder, but when you create a folder you may want to mask the results of the creation:

$null = New-item-path c:\newfolderA-ItemType directory

new-item-path c:\newfolderB-ItemType Directory | Out-null

So which way is better? Must be the first one. The pipeline passes unwanted results to out-null, which consumes more time and resources. Of course, you don't have to worry about the resources that are consumed by individual calls, but when you're in a loop, the effect will be obvious.

So the best way to compare out-null is to use $null.

Supports all PS versions

Related Article

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.