Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created January 23, 2019 01:39
Show Gist options
  • Select an option

  • Save ebibibi/cc5a65b50d066ce4900a028a77248f54 to your computer and use it in GitHub Desktop.

Select an option

Save ebibibi/cc5a65b50d066ce4900a028a77248f54 to your computer and use it in GitHub Desktop.
スクリプトにパスワードまで生で記載する形のExchange Onlineへの接続スクリプト(セキュリティには注意)
# Exchange OnlineへのPowerShell接続(※多要素認証には非対応)
#
# 1. O365組織の管理者のIDとパスワードを生で記載する
# 2. 管理者として実行したPowerShellに貼り付ける
# 3. 作業する
# 4. 作業が終わったら Remove-Session $Session を実行する
#
# 参考:https://docs.microsoft.com/ja-jp/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps
Set-ExecutionPolicy RemoteSigned
$ID = "xxxxx@xxxxx.onmicrosoft.com" # ID
$PlainPassword = 'xxxxxxx' # Password
#--------------------
$SecurePassword = ConvertTo-SecureString –String $PlainPassword –AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($ID, $SecurePassword)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
#--------------------
# 作業終了後
#--------------------
Remove-Session $Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment