Get the App
SLTechnology News&Howtos  ›  Servers  › 

Exchange/Office365 automatic processing script: common functions (1)

Shulou Source: shulou.com Published: 2022-06-02 03:13:18 09月28日 Update

Create a custom function script

1. Create a file named Microsoft.PowerShell_profile.ps1 under C:\ Users\ current login user name\ Documents\ WindowsPowershell

2. Open Microsoft.PowerShell_profile.ps1 and use Powershell ISE to add the following functions

Function 1: credential

Function exchangeaccountname {$account= "exchangeaccountname@genomics.cn" $password = ConvertTo-SecureString "Account Password"-asplaintext-force$cred=new-object-typename System.Management.Automation.PSCredential-argumentlist $account,$passwordreturn $cred} function skypeaccountname {$account= "skypeaccountname@genomics.cn" $password = ConvertTo-SecureString "Account Password"-asplaintext-force$cred=new-object-typename System.Management.Automation.PSCredential-argumentlist $account,$passwordreturn $cred} function o365accountname {$account= "O365accountname@genomics.cn" $password = ConvertTo-SecureString "Account Password"-asplaintext-force$cred=new-object-typename System.Management.Automation.PSCredential-argumentlist $account,$passwordreturn $cred}

Function 2: connect to Exchange 2010 Universe 2013 Server

Function connectoExchange {$ConnectionUri = "http://cas01.domain.cn/PowerShell/","http://cas02.domain.cn/PowerShell/" # modify the link to Exchange Cas$thisConnectionUri = $ConnectionUri | Get-Random$cred = exchangeaccountname # here use the credential function echo $thisConnectionUri$Session = New-PSSession-ConfigurationName Microsoft.Exchange-ConnectionUri$ thisConnectionUri-Authentication Kerberos-Credential $credImport-PSSession $Session-AllowClobber}

Function 2: connect to Skype for Business 2015

Function localskype {$cred= skypeaccountname # use the credential function $so = New-PSSessionOption-SkipCACheck:$true-SkipCNCheck:$true-SkipRevocationCheck:$true$Session = New-PSSession-ConnectionUri "https://sfbfe01.domain.cn/ocspowershell"-Credential $cred-SessionOption $soImport-PSSession $Session # here to modify the link to skype front end}

Function 3: connect to Office365

Function O365 {import-module MSonline# enter Office365 administrator account and password $credential = o365accountname # credential function Connect-MsolService-Credential $credential$exchangeSession = New-PSSession-ConfigurationName Microsoft.Exchange-ConnectionUri "https://outlook.office365.com/powershell-liveid/"-Credential $credential-Authentication" Basic "- AllowRedirectionImport-PSSession $exchangeSession-AllowClobber} is used here

An example is to connect to the international version of Office365.

If you connect to 21Vianet, use the _ ConnectionUri_ value: https://partner.outlook.cn/PowerShell

If you connect to German Office 365, use the _ ConnectionUri_ value: https://outlook.office.de/powershell-liveid/

Tags: Function credential link script front end name international international version password file user user name sample administrator account Germany login administration input commonly used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei MariaDB NVidia Xiaomi