Exchange the PowerShell transfer files and parallel pipelines

Source: Internet
Author: User

since Exchange Management Shell command is via remote PowerShell session execution, import and export files require a new specific parameter. There are hundreds of shell commands that need to be used, and in This section we'll look at how to use these parameters to transfer files through a remote Shell connection.

How the transfer file works:

Suppose you are creating an edge subscription hub to a transport server in the current Active Directory site. After you have generated the XML file on the Edge server , you can pass the new-edgesubscription command with the following syntax:

[byte[]] $data = Get-content-path "C:\certificates\ExportedCert.pfx"

-encoding Byte '

-readcount 0

$password = get-credential

Import-exchangecertificate–filedata $data –password $password

in this example, the first file is read into the variable $data the. The import of the certificate is using the command import-exchangecertificate command, by assigning the $data variable as the -filedata The value of the parameter.

There are a lot of Exchange Management Shell need to use -filedata parameters, such as:

import-dlppolicycollection: for import DLP Policy collection to organization

import-dlppolicytemplate: for import DLP policy templates to organization

import-exchangecertificate: for importing Certificates

import-journalrulecollection: for import Journal rules

Import-recipientdataproperty: for importing pictures or audio to Active Directory

import-transportrulecollection: used to import transport rules

import-umprompt: used to import custom audio files to UM in

Here's an example, assuming we need to export a photo of the user in the Active Directory and link to the mailbox, the command is as follows:

Export-recipientdataproperty-identity Dsmith-picture | %{

$_. FileData | Add-content C:\pics\dsmith.jpg-Encoding Byte

}

when we pass the parameters -picture Use Export-recipientdataproperty command, the photo is passed FileData property is retrieved again. The photo is stored in this property and acts as a Bytes array. In order to export this data, we need to use loops for each stored in FileData property, and then by using the add-content The command reconstructs the image into an external file.

working with remote PowerShell parallel Pipelines

When using remote PowerShell session, you may encounter a problem that is a parallel pipeline error. This can be a common mistake for many administrators, but you know that all of the Exchange Management shells are done through remote PowerShell . Parallel pipeline errors tend to be counter-intuitive, because the same command syntax works correctly in a standard PowerShell . In this section, I'll look at how we avoid it when parallel pipeline errors are encountered.

Remote PowerShell It is not supported to execute multiple pipelines at the same time. When you want to execute multiple commands in a pipeline, you need to save the output in a variable and then pass the pipeline to another command. For example, we need to pass the mailbox collection through the pipeline to the new-inboxrule command, using the following syntax to avoid parallel pipeline errors:

$mailboxes = get-mailbox-database "Mailbox Database 1014271532"

$mailboxes | %{

New-inboxrule-name Attach '

-mailbox $_ '

-hasattachment $true '

-markimportance High

}

650) this.width=650; "title=" 01.png "style=" height:490px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/67/wkiol1tsegrgtu23aanbr09tssk442.jpg "width=" 720 "height=" 490 "alt=" Wkiol1tsegrgtu23aanbr09tssk442.jpg "/>

in the example above, we first used the variable $mailboxes stores a mailbox database that belongs to Mailbox Database 1014271532 the collection of mailboxes in the. This is followed by a loop for each mailbox object, piped $mailboxex to the foreach-object command, and% is used in the example above alias substitution. Then, for each item in the collection, as long as the message contains the attachment, we mark it as important.

someExchange Management ShellThe command is specifically designed to accept output from other commands. A good example of this isGet-mailboxand theSet-mailbox. You can simply pass the pipeGet-mailboxcommand is passed directly toSet-mailboxcommand, and some parameters are automatically bound. You should have noticed thatGet-mailboxand theNew-inboxruleis not specifically designed, then you need to useForeach-objectcommand, orforeachLoop statement to pass the output information.

in a regular PowerShell session, you can normally pass a command to another command through the pipeline, but the remote PowerShell Session, PowerShell It is not supported to execute multiple pipelines at the same time.

we try to pipe the Get-mailbox delivered directly to Foreach-object, the following error will appear:

650) this.width=650; "title=" 02.png "style=" height:83px;width:720px; "border=" 0 "hspace=" 0 "src=" http://s3.51cto.com /wyfs02/m02/59/6b/wkiom1tser-rstvvaaeeifmzfmq690.jpg "width=" 720 "height=" "alt=" Wkiom1tser-rstvvaaeeifmzfmq690.jpg "/>

but this is Exchange SP1 after the fix, you look at the following results:

650) this.width=650; "title=" 03.png "style=" height:385px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m00/59/67/wkiol1tsegqsqrdmaapsdxw5ryo226.jpg "width=" 720 "height=" 385 "alt=" Wkiol1tsegqsqrdmaapsdxw5ryo226.jpg "/>

In the example above, we can also use the following syntax:

foreach ($i in get-mailbox–database ' Mailbox Database 1014271532 ') {

New-inboxrule-name Attach '

-mailbox $i '

-hasattachment $true '

-markimportance High

}

650) this.width=650; "title=" 04.png "style=" height:373px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m00/59/6b/wkiom1tsescaanddaakjyiimmne517.jpg "width=" 720 "height=" 373 "alt=" Wkiom1tsescaanddaakjyiimmne517.jpg "/>

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

Exchange the PowerShell transfer files and parallel pipelines

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.