资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Exchange/Office365自动处理脚本:常用函数(一)

创建自定义函数脚本
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/


名称栏目:Exchange/Office365自动处理脚本:常用函数(一)
路径分享:http://cdkjz.cn/article/pjjeod.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220