【发布时间】:2016-11-28 19:44:59
【问题描述】:
我正在编写一个 PowerShell 脚本,但我在使用枚举类型时遇到了困难。我对 SharePoint Online 执行 REST 调用以获取有关特定组的信息。
$group = Invoke-SPORestMethod -Url "https://tenant.sharepoint.com/sites/site/_api/web/RoleAssignments/GetByPrincipalId(8)?`$expand=RoleDefinitionBindings"
$group.RoleDefinitionBindings.results[0].RoleTypeKind
它返回一个 int,RoleTypeKind,它是 [Microsoft.SharePoint.Client.RoleType] 中的一个枚举。我在访问关联枚举值的 name 属性时遇到了困难。我目前正在这样做,但它似乎非常错误:
function getGroupPermissionKind([int]$roleType){
#https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.roletype.aspx
[Enum]::GetValues([Microsoft.SharePoint.Client.RoleType]) | foreach {
$Name = $_
$Value = ([Microsoft.SharePoint.Client.RoleType]::$_).value__
if ($Value -eq $roleType){
return $Name
}
}
}
知道$group.RoleDefinitionBindings.results[0].RoleTypeKind 返回枚举的正确int,我怎样才能更直接地访问枚举的名称,而不是使用我想出的看似笨拙的实现?
【问题讨论】:
标签: rest powershell enums office365 sharepoint-online