創建自定義函數腳本
1,在C:\Users\當前登錄用戶名\Documents\WindowsPowershell下創建名稱為Microsoft.PowerShell_profile.ps1 的文件
2,打開Microsoft.PowerShell_profile.ps1,使用Powershell ISE添加以下函數
函數1:憑據
function exchangeaccountname
{
$account="exchangeaccountname@genomics.cn"
$password = ConvertTo-SecureString "Account Password" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist $account,$password
return $cred
}
function skypeaccountname
{
$account="skypeaccountname@genomics.cn"
$password = ConvertTo-SecureString "Account Password" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist $account,$password
return $cred
}
function o365accountname
{
$account="O365accountname@genomics.cn"
$password = ConvertTo-SecureString "Account Password" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist $account,$password
return $cred
}
函數2:連接到Exchange 2010/2013 Server
function connectoExchange
{
$ConnectionUri = "http://cas01.domain.cn/PowerShell/","http://cas02.domain.cn/PowerShell/" #此處將鏈接修改為Exchange Cas
$thisConnectionUri = $ConnectionUri | Get-Random
$cred = exchangeaccountname #此處使用憑據函數
echo $thisConnectionUri
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $thisConnectionUri -Authentication Kerberos -Credential $cred
Import-PSSession $Session -AllowClobber
}
}
函數2:連接到Skype for Business 2015
function localskype
{
<#
.Synopsis
連接到skype for business 2015
#>
$cred= skypeaccountname #此處使用憑據函數
$so = New-PSSessionOption -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true
$Session = New-PSSession -ConnectionUri "https://sfbfe01.domain.cn/ocspowershell" -Credential $cred -SessionOption $so
Import-PSSession $Session #此處將鏈接修改為skype前端
}
函數3:連接到Office365
function O365
{
<#
.Synopsis
連接到Office365
#>
import-module MSonline
#輸入Office365管理員賬號和密碼
$credential = o365accountname #此處使用憑據函數
Connect-MsolService -Credential $credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -AllowClobber
}
示例為連接國際版Office365。
如連接21Vianet,使用_ConnectionUri_值:https://partner.outlook.cn/PowerShell
如連接德國Office 365,使用_ConnectionUri_值:https://outlook.office.de/powershell-liveid/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。