Delete a DesktopGroup

# —————————————————————————————————
#PowerShell sample script to delete a desktop group and related objects from a XenDesktop 5.x site
#
#Note: One or more required values must be specified below before executing the script.
#
#
#
#Version 1.0
#———————————————————————————————–

#Provide the following values before executing:

#The FQDN for the DDC and XML port, if not the default of 80
#Eg: ‘ddc01.domain.com:80’
$ddcAddress = ”

#The name of the desktop group to be removed
$desktopGroupName = ”

#End of variables
#******************************************************************
asnp Citrix.*

#Get a collection of the desktops in the desktop group
$desktops = Get-BrokerDesktop -DesktopGroupName $desktopGroupName -AdminAddress $ddcAddress

#Get the machine UIDs for each desktop
$machineUids = $desktops | ForEach {$_.MachineUid}

#Use the collection of machine UIDs to remove them from the desktop group
Remove-BrokerMachine -InputObject $machineUids -DesktopGroup $desktopGroupName -AdminAddress $ddcAddress

#Get the access policy rules with the desktop group as an included desktop group
$aprs = Get-BrokerAccessPolicyRule -IncludedDesktopGroup $desktopGroupName -AdminAddress $ddcAddress

#Loop through the access policy rules
ForEach ($apr in $aprs) {

#Determine if the desktop group is the only referenced by the rule
If ($apr.IncludedDesktopGroups.Length -eq 1) {

#The desktop group is the only one referencing this rule; remove the rule
Remove-BrokerAccessPolicyRule -Name $apr.Name -AdminAddress $ddcAddress
} ElseIf ($apr.IncludedDesktopGroups.Length -gt 1) {

#This rule is being applied to more than one desktop group
#Get a list of the desktop groups with the (target) desktop group removed
$dgs = $apr.IncludedDesktopGroups | Where-Object { $_.Name -ne $desktopGroupName}

#Set the access policy rule to use the updated desktop groups list (sans target desktop group)
Set-BrokerAccessPolicyRule -Name $apr.Name -IncludedDesktopGroups $dgs -AdminAddress $ddcAddress
}
}

#Get the desktop group object for the desktop group
$desktopGroup = Get-BrokerDesktopGroup -Name $desktopGroupName -AdminAddress $ddcAddress

#Get the entitlement policy rules applied to this desktop group
$eprs = Get-BrokerEntitlementPolicyRule -DesktopGroupUid $desktopGroup.Uid -AdminAddress $ddcAddress

#Remove each entitlement policy rule
ForEach ($epr in $eprs) {
Remove-BrokerEntitlementPolicyRule -Name $epr.Name -AdminAddress $ddcAddress
}

#Remove the desktop group
Remove-BrokerDesktopGroup -Name $desktopGroupName -AdminAddress $ddcAddress

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值