Two mistakes in writing PowerShell scripts today

Source: Internet
Author: User

Probably because the toothache did not sleep well, today is always making mistakes, or the script is wrong, especially difficult to adjust.

First error:

In a PowerShell script, functions and functions call each other's arguments. In fact, just like calling a normal cmdlet, you should write this:

$adminAddr $newScope $objectList

Look what I wrote:

Add-scopeobject ($adminAddr$newScope$objectList)

The results of the implementation of the wrong, I am anxious ah. I'm in the Add-scopeobject function crazy printing parameters:

    $adminAddr >> C:\Users\admin\Desktop\ output \adminaddr222.txt    $name >> C : \users\admin\desktop\ output \name222.txt    $objectList >> C:\Users\admin\Desktop\ output \ ObjectList222.txt

Results The first output txt inside all the parameters are printed out, the second and the third TXT file nothing. And then I was anxious about this. I'll find out how to @psboundparameters.

This thing has been looked at. Then suddenly remembered, your sister, not just like a cmdlet to preach, I have written before, rely on, silly fork!

A second error:

The second more tease, I write functions in PowerShell, originally my name and cmdlet do not coincide, the result of a road, thinking of people named multi-standard Ah, I will change the function name to someone else's cmdlet name,

The cmdlet is then called inside. This is hilarious ah, because of recursion, I print the parameters of crazy, down La Ala AH pull not the end, and then I carefully read my Code, logic is right AH!!! I'm more grumpy.

I go to the toilet, eat fruit, suddenly found, incredibly is this problem ... Really want to cry no tears ah, I this day is so grumpy past! Headache, upset ...

Two mistakes in writing PowerShell scripts today

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.