O365中的PowerShell编码

时间:2016-11-12 02:41:06

标签: powershell scripting

我对示例代码有疑问。我在O365中运行一些脚本,“运行脚本”如下所示。我想要在PSSession进入“Broken”状态时执行,它将暂停脚本,并删除损坏的会话(Remove-PSSession)并重新连接PSSession(在“重新连接代码”之后如下),然后重新启动脚本。我试着写这个,但我不熟悉编码....有人可以帮忙吗?..... (Server 2008 R2 SP1 / PowerShell) 任何帮助都会得到满足。

运行脚本-----

Import-Csv D:\work\users.csv | ForEach {
Grant-CsConferencingPolicy $_.UserPrincipalName -PolicyName BposSAllModalityNoFT}

Import-Csv D:\work\users.csv | ForEach {
Grant-CsExternalAccessPolicy $_.UserPrincipalName -PolicyName FederationOnly}

重新连接代码-------

$sfboSession = New-CsOnlineSession -Credential $credential
Import-Pssession $sfboSession -AllowClobber

1 个答案:

答案 0 :(得分:0)

`Import-csv D:\ IDMaster \ Tools \ SkypeTool \ users.txt | foreach {

 Do {

     Grant-CsConferencingPolicy $_.UserPrincipalName -PolicyName BposSAllModalityNoFT

if($?-ne" True")          {              get-pssession |除去-的PSSession              $ sfboSession = New-CsOnlineSession -credential $ credential              Import-PSSession $ sfboSession -AllowClobber}        }#结束'做'      直到($?-eq" True")          Write-Host $ _。UserPrincipalName" BposSAllModalityNoFT"

 Do {
     Grant-CsExternalAccessPolicy $_.UserPrincipalName -PolicyName FederationAndPICDefault

if($?-ne" True")          {              get-pssession |除去-的PSSession              $ sfboSession = New-CsOnlineSession -credential $ credential              Import-PSSession $ sfboSession -AllowClobber}        }#结束'做'      直到($?-eq" True")          Write-Host $ _。UserPrincipalName" FederationAndPICDefault"

     $string = $_.UserPrincipalName + " " + "BposSAllModalityNoFT" + " " + "FederationAndPICDefault" 
     Write-Output $string | Out-file D:\IDMaster\Tools\SkypeTool\Modify_Log.csv -Append -Encoding default

}`

相关问题