成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何安全連接Office 365 Online

開發 前端
隨著Office 365在中國的迅速普及,越來越多的公司開始使用Office 365及相關服務。能夠熟練使用并管理Office 365 就成為廣大公司IT管理員的一個必備技能。

隨著Office 365 在中國的迅速普及,越來越多的公司開始使用Office 365及相關服務。能夠熟練使用并管理Office 365 就成為廣大公司IT管理員的一個必備技能。

[[312358]]

今天我們就來介紹一種較為安全便捷的方式的連接Office 365 Online,即在PowerShell界面,通過加密用戶名和密碼的方式連接Office 365 Online。那我們使用PowerShell對Office 365 Online進行遠程管理,有如下優點:

  • Office 365 擁有僅可使用 Office 365 PowerShell 配置的功能
  • Office 365 PowerShell 善于執行批量操作
  • Office 365 PowerShell 善于篩選數據
  • Office 365 PowerShell 方便打印或保存數據
  • Office 365 PowerShell 支持跨服務器產品管理
  • Office 365 PowerShell 會顯示無法通過 Microsoft 365 管理中心看到的其他信息

在連接過程中,如果用戶名和密碼以明文形式輸入,就會帶來安全風險。如果采用以下PowerShell腳本就可以避免這個缺點:預先定義兩個函數,分別用于加密和解密字符串;然后檢查本地是否存在已經加密的用戶名和密碼文件,如果沒有,提示用戶輸入用戶名和密碼,并將其以密文形式存到本地;最后,讀取本地加密的用戶名和密碼,并將其解密,用于遠程連接Office 365 Online。

腳本代碼分為以下三個部分介紹給大家。

第一部分,定義加密和解密的函數。 

  1. # This function is to encrypt a string. 
  2. function Encrypt-String($String, $Passphrase, $salt="SaltCrypto", $init="IV_Password", [switch]$arrayOutput)  
  3. {  
  4.     $r = new-Object System.Security.Cryptography.RijndaelManaged  
  5.     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)  
  6.     $salt = [Text.Encoding]::UTF8.GetBytes($salt)  
  7. $r.Key = (new-Object ` 
  8.                   Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32)  
  9. $r.IV = (new-Object ` 
  10.               Security.Cryptography.SHA1Managed).ComputeHash ` 
  11.               [Text.Encoding]::UTF8.GetBytes($init) )[0..15]  
  12.     $c = $r.CreateEncryptor()  
  13.     $ms = new-Object IO.MemoryStream  
  14.     $cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write"  
  15.     $sw = new-Object IO.StreamWriter $cs  
  16.     $sw.Write($String)  
  17.     $sw.Close()  
  18.     $cs.Close()  
  19.     $ms.Close()  
  20.     $r.Clear()  
  21.     [byte[]]$result = $ms.ToArray()  
  22.     return [Convert]::ToBase64String($result)  
  23. }  
  24.  
  25. # This function is to de-encrypt a string. 
  26. function Decrypt-String($Encrypted, $Passphrase, $salt="SaltCrypto", $init="IV_Password")  
  27. {  
  28.     if($Encrypted -is [string]){  
  29.         $Encrypted = [Convert]::FromBase64String($Encrypted)  
  30.        }  
  31.     $r = new-Object System.Security.Cryptography.RijndaelManaged  
  32.     $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)  
  33.     $salt = [Text.Encoding]::UTF8.GetBytes($salt)  
  34. $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes ` 
  35.                  $pass, $salt, "SHA1", 5).GetBytes(32) 
  36. $r.IV = (new-Object ` 
  37.               Security.Cryptography.SHA1Managed).ComputeHash ` 
  38.               ( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]  
  39.     $d = $r.CreateDecryptor()  
  40.     $ms = new-Object IO.MemoryStream @(,$Encrypted)  
  41.     $cs = new-Object Security.Cryptography.CryptoStream $ms,$d,"Read"  
  42.     $sr = new-Object IO.StreamReader $cs  
  43.     Write-Output $sr.ReadToEnd()  
  44.     $sr.Close()  
  45.     $cs.Close()  
  46.     $ms.Close()  
  47.     $r.Clear()  
  48. Clear-Host 

第二部分,從本地的文本文件中讀取加密的Office 365用戶名和密碼。只第一次需要手工輸入用戶名和密碼,然后將加密的用戶名和密碼以密文形式存儲到本地磁盤。此后無需輸入。 

  1. #Try to read the encrypted user name and password from the specific path, if there are, read and de-encrypt them. If there are not, prompt for input and encrypt them. 
  2. $uencrypted = Get-Content -ErrorAction SilentlyContinue -Path 'C:\$Home\Desktop\Username.txt' 
  3. $pencrypted = Get-Content -ErrorAction SilentlyContinue -Path 'C:\$Home\Desktop\password.txt' 
  4. If ($null -ne $uencrypted -and $null -ne $pencrypted) 
  5.     $udecrypted = Decrypt-String $uencrypted "U_MyStrongPassword" 
  6.     $pdecrypted = Decrypt-String $pencrypted "P_MyStrongPassword" 
  7.     $pdecrypted = ConvertTo-SecureString $pdecrypted -AsPlainText -Force 
  8. Else 
  9.     $ustring = read-host "Please Enter Office 365 User name"  
  10.     $pstring = read-host "Please Enter Office 365 User Password"  
  11.     $uencrypted = Encrypt-String $ustring "U_MyStrongPassword" 
  12.     $uencrypted | Out-File "$HOME\Desktop\Username.txt" 
  13.     write-host "Store the encrypted Username successfully!"  
  14.     $pencrypted = Encrypt-String $pstring "P_MyStrongPassword" 
  15.     $pencrypted | Out-File "$HOME\Desktop\password.txt" 
  16.     write-host "Store the encrypted password successfully!" 
  17.     $udecrypted = Decrypt-String $uencrypted "U_MyStrongPassword" 
  18.     $pdecrypted = Decrypt-String $pencrypted "P_MyStrongPassword" 
  19.     $pdecrypted = ConvertTo-SecureString $pdecrypted -AsPlainText -Force 

第三部分,連接Office 365 Online。 執行以下命令后,就可以在PowerShell下,遠程管理Office 365 Exchange Online了。 

  1. #Connect to Office 365 online or Azure 
  2. $LiveCred = New-Object System.Management.Automation.PSCredential $udecrypted, $pdecrypted     
  3. $Session = New-PSSession -ConfigurationName Microsoft.Exchange ` 
  4.                      -ConnectionUri https://partner.outlook.cn/powershell -Credential $LiveCred ` 
  5.                      -Authentication Basic –AllowRedirection -ErrorAction Stop ` 
  6.                      -Name "$($Credential.UserName)" 
  7. Import-PSSession $Session 
  8. Connect-MsolService –Credential $LiveCred -AzureEnvironment AzureChinaCloud 

注意:執行最后一個命令,需要預先安裝Microsoft Online Services Sign-In Assistant。安裝方法可自行百度,本篇不做介紹。

 

責任編輯:華軒 來源: 世紀互聯藍云
相關推薦

2014-12-24 09:32:16

2013-06-27 09:45:56

2012-11-13 17:02:34

Office 365

2014-04-15 13:39:54

企業Office 36Office 365遷

2013-08-01 09:48:58

微軟Office 365

2013-01-29 14:29:44

Office 2013Office 365

2013-02-28 20:28:19

Office 365Office 201微軟

2013-01-30 15:22:13

Office 365

2013-02-28 20:20:17

2017-11-01 13:54:41

微信Office 365

2013-12-06 13:39:18

TechEd2013

2013-05-02 10:17:34

Google AppsOffice 365

2013-03-20 10:33:29

Office 365微軟

2015-03-20 13:40:17

2013-07-18 09:28:23

微軟Office 365Google

2018-04-08 10:44:37

Office

2014-11-26 10:03:10

AzureADOffice365ADFS

2015-09-23 11:33:42

Office 365Windows 10微軟

2011-06-30 08:56:15

微軟云計算Office 365

2011-12-19 14:19:03

Office 365云計算云應用
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久久精品一区 | 天天综合久久 | av色站 | 亚洲天堂中文字幕 | 91精品国产综合久久精品 | 午夜丰满少妇一级毛片 | 国产精品成人国产乱一区 | sese视频在线观看 | 成人欧美一区二区三区黑人孕妇 | 亚洲精品91 | 亚洲电影一区二区三区 | 亚洲一区二区电影网 | 日韩精品色网 | 一级片在线观看 | 欧洲免费视频 | 精品视频久久久久久 | 欧美中文在线 | 亚洲iv一区二区三区 | 婷婷免费在线 | 国产精品欧美日韩 | 在线看亚洲 | 日韩av免费在线观看 | 国产伦精品一区二区三区照片91 | wwwxxx日本在线观看 | 羞羞视频在线观看 | 欧美亚洲成人网 | 韩日精品视频 | 91久久国产综合久久 | 91视频播放| 亚洲成人观看 | 日韩欧美三区 | 日本三级网址 | 国产精品s色 | 老牛影视av一区二区在线观看 | 中文字幕第九页 | 中文字幕一区二区三区四区五区 | 国产一级精品毛片 | 18成人在线观看 | h片在线看 | 成人黄色在线观看 | 欧美一区二区在线播放 |