-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750
When we use PowerShell to create a mailbox, there are two ways to fill in the password
Method 1, enter the password manually
$password = read-host "Enter password"-assecurestring
New-mailbox-userprincipalname [email protected] -alias chris-database "Mailbox Database 1"-name Chrisashton-o Rganizationalunit users-password $password-firstname chris-lastname ashton-displayname "Chris Ashton"-resetpasswordo Nnextlogon $true
Method 2, use plaintext password in encrypted use
New-mailbox-userprincipalname [email protected] -alias chris-database "Mailbox Database 1"-name Chrisasht On-organizationalunit Users-password (convertto-securestring-string [email protected]-asplaintext-force) - FirstName chris-lastname ashton-displayname "Chris Ashton"-resetpasswordonnextlogon $true
Method 1 is not very convenient to use, each new account to enter a password, Method 2 is easy to use to cause the password to be seen by others, security is not guaranteed, we how to ensure that the password is created without each input, but also ensure that security is guaranteed. The method is to use ciphertext password.
Step 1, encrypt the password and keep it to c:\xxx.txt.
$mysecret = "Passw0rd"
$mysecret | Convertto-securestring-asplaintext-force | Convertfrom-securestring| Out-file c:\xxx.txt-Encoding UTF8
Step 2, convert the ciphertext password into a format that PowerShell can use
$securestring = (get-content C:\xxx.txt). ToString () | Convertto-securestring
$ptr = [System.runtime.interopservices.marshal]::securestringtoglobalallocunicode ($secureString)
$serverpass = [System.Runtime.InteropServices.Marshal]::P trtostringuni ($PTR)
$Password = convertto-securestring $serverpass-asplaintext–force
Step 3, create the mailbox when the $password variable is called.
New-mailbox-userprincipalname [email protected] -alias chris-database "Mailbox Database 1"-name chrisashton-organizationalunit users-password $password-firstnam E chris-lastname ashton-displayname "Chris Ashton"-resetpasswordonnextlogon $true
When we connected to PowerShell, we found a place that was especially annoying, and each time we had to enter a username and password, for example.
650) this.width=650; "Width=" "height=" 441 "title=" QQ picture 20150213165046.png "style=" WIDTH:716PX;HEIGHT:239PX; "alt = "Wkiol1tdu_whq-5daaqvurjz31i212.jpg" src= "Http://s3.51cto.com/wyfs02/M01/59/BB/wKioL1Tdu_WhQ-5dAAQVuRJZ31I212.jpg"/>
In fact, we can convert this password into ciphertext password to save it for PowerShell to call directly, the command is as follows:
$securestring = (get-content C:\xxx.txt). ToString () | convertto-securestring
$ptr = [System.runtime.interopservices.marshal]::securestringtoglobalallocunicode ($ secureString)
$serverpass = [System.Runtime.InteropServices.Marshal]::P trtostringuni ($ptr)
$UserName = " Span style= "font-family: ' Microsoft Jacob Black '; font-size:14px;" >[email Protected] #定义管理员账户名称
$Password = convertto-securestring $serverpass- Asplaintext–force
$cred = New-object System.Management.Automation.PSCredential ($UserName, $Password)
$ Session=new-pssession-configurationname Microsoft.exchange-connectionuri Https://mail.rightdo.net/powershell- Authentication basic-credential $cred
import-pssession $sessionImport-pssession $session
After entering PowerShell, the connection is normal.
650) this.width=650; "Width=" 1042 "height=" 830 "title=" QQ picture 20150213165046.png "style=" WIDTH:716PX;HEIGHT:401PX; "alt = "Wkiol1tdxtmxasieaayx7uyfdew842.jpg" src= "Http://s3.51cto.com/wyfs02/M00/59/BB/wKioL1TdxTmxasiEAAYX7UyFDEw842.jpg"/>
There is encryption at the same time there is a decryption method, the ciphertext converted back to clear text (can only be decrypted on the computer used for encryption)
$secureString = Get-content-path C:\xxx.txt | Convertto-securestring
$ptr = [System.runtime.interopservices.marshal]::securestringtoglobalallocunicode ($secureString)
$mysecret = [System.Runtime.InteropServices.Marshal]::P trtostringuni ($PTR)
$mysecret
650) this.width=650; "Width=" 798 "height=" 664 "title=" QQ picture 20150213165046.png "style=" width:711px;height:495px; "alt= "Wkiol1tdxmmxv8rlaaj1tpijiva611.jpg" src= "Http://s3.51cto.com/wyfs02/M01/59/BB/wKioL1TdxmmxV8RlAAJ1TPiJivA611.jpg"/>
This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1614363
PowerShell Management Series (23) PowerShell operation using ciphertext password to create a mailbox and connect to PowerShell