Exchange A PowerShell Create a custom script

Source: Internet
Author: User

we can do a lot of things by executing a single command or by running multiple commands with a pipeline, but sometimes you want to create a script, perform a series of operations, or load a library or a predefined variable or alias Shell , in this section, we'll learn to create scripts and run scripts

How do you do it?

1. Let's create a basic script to automate a multi-step process. To enable the text editor, enter the following code:

Param

$name,

$maxsendsize,

$maxreceivesize,

$city,

$state,

$title,

$department

)

Set-mailbox-identity $name '

-maxsendsize $maxsendsize '

-maxreceivesize $maxreceivesize

Set-user-identity $name '

-city $city '

-stateorprovince $state '

-title $title '

-department $department

add-distributiongroupmember-identity Technical Center `

-member $name

2. Next, we'll change the file to the following path c:\Update-SalesMailbox.ps1

3. Start running the script below

C:\Update-SalesMailbox.ps1-name TestUser '

-maxsendsize 25MB '

-maxreceivesize 25MB '

-city Phoenix '

-state AZ '

-title Manager '

-department Sales

650) this.width=650; "title=" 01.png "style=" height:54px;width:720px; "border=" 0 "hspace=" 0 "src=" http://s3.51cto.com /wyfs02/m01/59/1e/wkiom1thtq_a3oboaae-sqtr0i8030.jpg "width=" 720 "height=" alt= "Wkiom1thtq_" A3oboaae-sqtr0i8030.jpg "/>

Powershell operating principle

                    Powershell The concept of scripting is kind of like cmd.exe , batch files, etc. However, powershell is not a batch extension, powershell using the .ps1 extension. When creating a script, we can use a text editor for editing, or we can use the powershell ise edit

PowerShell just like a function, you can accept parameters. From the example above, we can see that through scripting we automatically modify the properties of the mailbox and add it to the distribution group. Because it involves three commands, we can use a script to automate the tasks we want to accomplish.

If we want to run a script to operate on a set of mailboxes, we can use the ForEach loop for processing, as shown in the following example:

foreach ($i in Get-mailbox-organizationalunit contoso.com/sales) {

C:\Update-SalesMailbox.ps1-name $i. Name '

-maxsendsize 100MB '

-maxreceivesize 100MB '

-city Phoenix '

-state AZ '

-title ' Sales Rep '

-department Sales

}

PowerShell script Execution Policy

Windows PowerShell Scripting Policy Security is designed to prevent some unsafe scripts from running in your environment by default with the following security policies:

1. Restricted: In this mode, some digitally signed scripts are also not allowed to run

2. AllSigned: In this mode, all signed scripts can be run

3. remotesigned: In this mode, only local scripts are allowed to run, and some scripts downloaded from the Internet are not allowed to run

4. Unrestricted: In this mode, all scripts can be run, whether they are signed or downloaded locally or from the Internet.

This article from "Robin's Home" blog, declined reprint!

Exchange A PowerShell Create a custom script

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.