脚本管理服务委托添加规则...和将用户添加到规则的问题 [英] Issues with scripting Management Service Delegation Add Rule... and Add User To Rule

查看:50
本文介绍了脚本管理服务委托添加规则...和将用户添加到规则的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell编写脚本,以在Windows Server 2016上的管理服务委派中添加角色并将用户添加到角色.不幸的是,我无法找到有关此操作的任何文档.

I am trying to script with Powershell adding a role and adding a user to the role on Management service delegation on Windows server 2016. Unfortunately I have not been able to find any documentation on how this is done.

我已经安装了Web deploy 3.6,并且可以在IIS中看到管理服务委托模块.

I have Web deploy 3.6 installed and can see the Management service delegation module in IIS.

我知道通过IIS UI这样做很简单,但是我需要通过powershell编写脚本.如果有人可以提供帮助,将不胜感激.

I know that doing this via the IIS UI is trivial but I need to get it scripted via powershell. If anyone could assist it would be really appreciated.

谢谢

推荐答案

我最终查看了WebDeploy AddDelegationRules.ps1脚本来弄清楚这一点.这将创建一个新的管理服务委托规则,并将用户添加到该规则中.

I ended up peeking into the WebDeploy AddDelegationRules.ps1 script to figure this one out. This will create a new Management service delegation rule and add a user to the rule.

$serverManager = (New-Object Microsoft.Web.Administration.ServerManager)
$delegationRulesCollection = $serverManager.GetAdministrationConfiguration()
.GetSection("system.webServer/management/delegation").GetCollection()


$newRule = $delegationRulesCollection.CreateElement("rule")
$newRule.Attributes["providers"].Value = $provider
$newRule.Attributes["actions"].Value = "*"
$newRule.Attributes["path"].Value = $path
$newRule.Attributes["pathType"].Value = $pathType
$newRule.Attributes["enabled"].Value = "true"

$runAs = $newRule.GetChildElement("runAs")
$runAs.Attributes["identityType"].Value = "CurrentUser"

$permissions = $newRule.GetCollection("permissions")
$user = $permissions.CreateElement("user")
$user.Attributes["name"].Value = "*"
$user.Attributes["accessType"].Value = "Allow"
$user.Attributes["isRole"].Value = "False"
$permissions.Add($user) | out-null

$delegationRulesCollection.Add($newRule) | out-null
$serverManager.CommitChanges()    

这篇关于脚本管理服务委托添加规则...和将用户添加到规则的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆