当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 自动启用和禁用 Lync/Skype for Business 用户

作者:精品下载站 日期:2024-12-14 08:13:42 浏览:15 分类:玩电脑

自动启用和禁用 Lync/Skype for Business 用户


当我看到管理员手动启用所有 Lync/Skype for Business 用户时,我感到有些畏缩。只需几行 PowerShell 和计划任务,您就可以自动为用户启用 Lync/Skype for Business。只需复制脚本示例并使用您的基础结构详细信息进行修改,然后通过远程处理在 Lync/Skype For Business 服务器或非 Lync/Skype for Business 服务器上制定计划任务。

首先要确定谁应该启用 Lync/Skype for Business 以及为这些用户提供的所需设置。我将提供启用或禁用用户的不同场景的示例。 (所有示例仅搜索当前未启用的 Lync/Skype for Business 用户,并假设电子邮件地址是启用的 SIP 地址。)

示例 #1:允许公司中具有与 @yourdomain.com 匹配的电子邮件帐户的所有用户正常使用 Lync。

Get-CsAdUser -Filter { Enabled -ne $True -and WindowsEmailAddress -like '*@yourdomain.com' } |
Enable-CsUser -RegistrarPool 'yourpool' -SipAddressType emailaddress

示例 #2:启用公司中特定 Active Directory OU 内的所有用户以及与 @yourdomain.com 匹配的电子邮件帐户以进行正常 Lync 使用。

Get-CsAdUser -OU 'your.domain.com/OU' -Filter { Enabled -ne $True -and WindowsEmailAddress -like '*@yourdomain.com' } |
Enable-CsUser -RegistrarPool 'yourpool' -SipAddressType emailaddress

示例 #3:启用公司中具有特定城市属性的所有用户,以便通过适当的注册商池正常使用 Lync。

Get-CsAdUser -Filter { Enabled -ne $True -and WindowsEmailAddress -like '*@yourdomain.com' -and City -eq 'YourCityName' } |
Enable-CsUser -RegistrarPool 'yourlocationdependantpool' -SipAddressType emailaddress

示例 #4:通过适当的注册商池和特定的位置策略,使公司中具有特定城市属性的所有用户能够正常使用 Lync。

$users = Get-CsAdUser -Filter { Enabled -ne $True -and WindowsEmailAddress -like '*@yourdomain.com' -and City -eq 'YourCityName' }
ForEach ($user in $users)
{
	Enable-CsUser $user.Identity -RegistrarPool 'yourlocationdependantpool' -SipAddressType emailaddress
	Grant-CsLocationPolicy -Identity $user.Identity -PolicyName 'yourlocationpolicy' -Confirm:$False
}

示例#5:通过特定的语音策略、拨号计划、会议策略、位置策略,为公司中具有特定城市属性的所有用户启用企业语音。 (如果需要,请在运行 Set-CsUser 命令时不要忘记唯一的线路 URI。)

$users = Get-CsAdUser -Filter { Enabled -ne $True -and WindowsEmailAddress -like '*@yourdomain.com' }
ForEach ($user in $users)
{
	Enable-CsUser -Identity $user.Identity -RegistrarPool 'yourlocationdependantpool' -SipAddressType emailaddress
	Set-CsUser -Identity $user.Identity -EnterpriseVoiceEnabled $True -Confirm:$False
	Grant-CsConferencingPolicy -Identity $user.Identity 'yourconferencingpolicy' -Confirm:$False
	Grant-CsDialPlan -Identity $user.Identity -PolicyName 'yourdialplan' -Confirm:$False
	Grant-CsLocationPolicy -Identity $user.Identity -PolicyName 'yourlocationpolicy' -Confirm:$False
	Grant-CsVoicePolicy -Identity $user.Identity -PolicyName 'yourvoicepolicy' -Confirm:$False
}

示例 #6:以下示例重点介绍 PowerShell Remoting,以从单独的计算机远程执行用户帐户的启用。

$serviceuser = 'serviceuser'
$servicepassword = 'servicepassword' | ConvertTo-SecureString -AsPlainText -Force
$servicecredential = New-Object system.Management.Automation.PSCredential($serviceuser, $servicepassword)
$lyncsession = New-PSSession -ConnectionUri 'https://yourpoolname/ocspowershell' -Credential $servicecredential
$emailaddress = '*@yourdomain.com'
Invoke-Command -Session $lyncsession -ScriptBlock {
	param ($emailaddress) Get-CsUser -Filter "WindowsEmailAddress -like '$emailaddress'" |
	Enable-CsUser -RegistrarPool 'yourpool' -SipAddressType emailaddress
} -ArgumentList $emailaddress
Remove-PSSession $lyncsession

示例#7:以下示例重点介绍了循环多个城市并根据该城市设置适当的池和策略。此示例使用包含所有城市及其各自设置的 .CSV 文件。您可以通过代码添加自定义对象,然后添加每个城市来完成相同的操作。首选使用 .CSV 文件,因为它允许您将来添加/删除城市而无需更改脚本。




$cities = Import-Csv cities.csv

ForEach ($city in $cities) {
	$users = Get-CsAdUser -Filter { Enabled -ne $True -and WindowsEmailAddress -like ‘*@yourdomain.com’ -and City -eq $city.Name }
	ForEach ($user in $users)
	{
		Enable-CsUser -Identity $user.Identity -RegistrarPool $city.RegistrarPool -SipAddressType emailaddress
		Set-CsUser -Identity $user.Identity -EnterpriseVoiceEnabled $True -Confirm:$False
		Grant-CsConferencingPolicy -Identity $user.Identity $city.ConferencingPolicy -Confirm:$False
		Grant-CsDialPlan -Identity $user.Identity -PolicyName $city.DialPlan -Confirm:$False
		Grant-CsLocationPolicy -Identity $user.Identity -PolicyName $city.LocationPolicy -Confirm:$False
		Grant-CsVoicePolicy -Identity $user.Identity -PolicyName $city.VoicePolicy -Confirm:$False
	}
}

以下是在 Active Directory 帐户被禁用的情况下自动禁用 Lync 用户的一些示例。

示例 #1:对 Active Directory 中已禁用的所有用户禁用 Lync/Skype for Business。

Get-CsAdUser -LDAPFilter "(&(userAccountControl:1.2.840.113556.1.4.803:=2)(msRTCSIP-UserEnabled=TRUE))" |
Disable-CsUser

示例 #2:从 Active Directory 中禁用的所有用户远程禁用 Lync/Skype for Business。

$serviceuser = 'serviceuser'
$servicepassword = 'servicepassword' | ConvertTo-SecureString -AsPlainText -Force
$servicecredential = New-Object system.Management.Automation.PSCredential($serviceuser, $servicepassword)
$lyncsession = New-PSSession -ConnectionUri 'https://yourpoolname/ocspowershell' -Credential $servicecredential
Invoke-Command -Session $lyncsession -ScriptBlock {
	Get-CsAdUser -LDAPFilter "(&(userAccountControl:1.2.840.113556.1.4.803:=2)(msRTCSIP-UserEnabled=TRUE))" |
	Disable-CsUser
}
Remove-PSSession $lyncsession

示例 #3:根据要求,以下是远程禁用 Active Directory 组中所有用户的 Lync/Skype for Business 的解决方案。这里的关键是调整 LDAP 过滤器以仅包含特定组的成员。

$serviceuser = 'serviceuser'
$servicepassword = 'servicepassword' | ConvertTo-SecureString -AsPlainText -Force
$servicecredential = New-Object system.Management.Automation.PSCredential($serviceuser, $servicepassword)
$lyncsession = New-PSSession -ConnectionUri 'https://yourpoolname/ocspowershell' -Credential $servicecredential
Invoke-Command -Session $lyncsession -ScriptBlock {
	Get-CsAdUser -LDAPFilter "(&(memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com)(msRTCSIP-UserEnabled=TRUE))" |
	Disable-CsUser
}
Remove-PSSession $lyncsession

请随意留下您所需场景的评论,我将用解决方案更新这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯