In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use PowerShell secure connection Office 365Online", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to use PowerShell secure connection Office 365 Online"!
In the PowerShell interface, connect to the Office 365 Online by encrypting the username and password. Then we use PowerShell to remotely manage Office 365 Online, which has the following advantages:
Office 365 has features that can only be configured using Office 365PowerShell
Office 365PowerShell is good at performing batch operations
Office 365PowerShell is good at filtering data.
Office 365 PowerShell makes it easy to print or save data
Office 365 PowerShell supports cross-server product management
Office 365 PowerShell displays additional information that cannot be seen through the Microsoft 365 Central Administration
During the connection process, if the user name and password are entered in clear text, there is a security risk. This disadvantage can be avoided by using the following PowerShell script: pre-define two functions to encrypt and decrypt strings; then check if the encrypted username and password file exists locally; if not, prompt the user for the username and password and store them locally in ciphertext; finally, read the locally encrypted username and password and decrypt it for remote connection to Office 365Online.
The script code is divided into the following three parts to introduce you.
The first part defines the functions of encryption and decryption.
# This function is to encrypt a string. Function Encrypt-String ($String, $Passphrase, $salt= "SaltCrypto", $init= "IV_Password", [switch] $arrayOutput) {$r = new-Object System.Security.Cryptography.RijndaelManaged $pass = [Text.Encoding]:: UTF8.GetBytes ($Passphrase) $salt= [Text.Encoding]:: UTF8.GetBytes ($salt) $r.Key = (new-Object `Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1") 5) .GetBytes (32) $r.IV = (new-Object `Security.Cryptography.SHA1Managed) .GetBytes `[Text.Encoding]:: UTF8.GetBytes ($init)) [0.15] $c = $r.CreateEncryptor () $ms = new-Object IO.MemoryStream $cs = new-Object Security.Cryptography.CryptoStream $ms,$c "Write" $sw = new-Object IO.StreamWriter $cs $sw.Write ($String) $sw.Close () $cs.Close () $ms.Close () $r.Clear () [byte []] $result = $ms.ToArray () return [Convert]: ToBase64String ($result)} # This function is to de-encrypt a string. Function Decrypt-String ($Encrypted, $Passphrase, $salt= "SaltCrypto" $init= "IV_Password") {if ($Encrypted-is [string]) {$Encrypted = [Convert]:: FromBase64String ($Encrypted)} $r = new-Object System.Security.Cryptography.RijndaelManaged $pass = [Text.Encoding]:: UTF8.GetBytes ($Passphrase) $salt = [Text.Encoding]:: UTF8.GetBytes ($salt) $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes `$pass, $salt, "SHA1" 5) .GetBytes (32) $r.IV = (new-Object `Security.Cryptography.SHA1Managed) .ComputeHash `([Text.Encoding]:: UTF8.GetBytes ($init)) [0.15] $d = $r.CreateDecryptor () $ms = new-Object IO.MemoryStream @ (, $Encrypted) $cs = new-Object Security.Cryptography.CryptoStream $ms,$d "Read" $sr = new-Object IO.StreamReader $cs Write-Output $sr.ReadToEnd () $sr.Close () $cs.Close () $ms.Close () $r.Clear ()} Clear-Host
The second part reads the encrypted Office username and password from the local text file. You only need to enter the user name and password manually for the first time, and then store the encrypted user name and password on the local disk in ciphertext. There is no need to enter after that.
# 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. $uencrypted = Get-Content-ErrorAction SilentlyContinue-Path'C:\ $Home\ Desktop\ Username.txt' $pencrypted = Get-Content-ErrorAction SilentlyContinue-Path'C:\ $Home\ Desktop\ password.txt' If ($null-ne $uencrypted-and $null-ne $pencrypted) {$udecrypted = Decrypt-String $uencrypted "U_MyStrongPassword" $pdecrypted = Decrypt-String $pencrypted "P_MyStrongPassword" $pdecrypted = ConvertTo-SecureString $pdecrypted-AsPlainText-Force} Else {$ustring = read-host "read-host" $ustring Read-host "Please Enter Office User Password" $uencrypted = Encrypt-String $ustring "U_MyStrongPassword" $uencrypted | Out-File "$HOME\ Desktop\ Username.txt" write-host "Store the encrypted Username successfully!" $pencrypted = Encrypt-String $pstring "P_MyStrongPassword" $pencrypted | Out-File "$HOME\ Desktop\ password.txt" write-host "Store the encrypted password successfully!" $udecrypted = Decrypt-String $uencrypted "U_MyStrongPassword" $pdecrypted = Decrypt-String $pencrypted "P _ MyStrongPassword "$pdecrypted = ConvertTo-SecureString $pdecrypted-AsPlainText-Force}
The third part is to connect Office 365Online. After executing the following command, you can remotely manage Office 365Exchange Online under PowerShell.
# Connect to Office 365online or Azure $LiveCred = New-Object System.Management.Automation.PSCredential $udecrypted, $pdecrypted $Session = New-PSSession-ConfigurationName Microsoft.Exchange `- ConnectionUri https://partner.outlook.cn/powershell-Credential $LiveCred`-Authentication Basic-AllowRedirection-ErrorAction Stop `- Name "$($Credential.UserName)" Import-PSSession $Session Connect-MsolService-Credential $LiveCred-AzureEnvironment AzureChinaCloud
Note: to execute the last command, you need to install Microsoft Online Services Sign-In Assistant beforehand.
At this point, I believe you have a deeper understanding of "how to use PowerShell secure connection Office 365 Online". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.