Forum Discussion
Add User dynamically to Power bi report server
Hi Adharrison,
Thank you for quick reply. I have gone through the suggested link and get to know that using some powershell command i can add user and assign the role for him.
I believe below code should fullfill my requirement:
Clear-Host
$ReportServerUri = 'http://PorteousSQL1/ReportServer/ReportService2010.asmx?wsdl'
$InheritParent = $true
$GroupUserName = 'Domain\Deploy'
$RoleName = 'Publisher'
$rsProxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential
$type = $rsProxy.GetType().Namespace;
$policyType = "{0}.Policy" -f $type;
$roleType = "{0}.Role" -f $type;
#List out all subfolders under the parent directory
$items = $rsProxy.ListChildren("/", $true) | `
SELECT TypeName, Path, ID, Name | `
Where-Object {$_.typeName -eq "Folder"}
#Iterate through every folder
foreach($item in $items)
{
$Policies = $rsProxy.GetPolicies($Item.Path, [ref]$InheritParent)
#Skip over folders marked to Inherit permissions. No changes needed.
if($InheritParent -eq $false)
{
#Return all policies that contain the user/group we want to add
$Policy = $Policies |
Where-Object { $_.GroupUserName -eq $GroupUserName } |
Select-Object -First 1
#Add a new policy if doesnt exist
if (-not $Policy)
{
$Policy = New-Object ($policyType)
$Policy.GroupUserName = $GroupUserName
$Policy.Roles = @()
#Add new policy to the folder's policies
$Policies += $Policy
}
#Add the role to the new Policy
$r = $Policy.Roles |
Where-Object { $_.Name -eq $RoleName } |
Select-Object -First 1
if (-not $r)
{
$r = New-Object ($roleType)
$r.Name = $RoleName
$Policy.Roles += $r
}
#Set folder policies
$rsProxy.SetPolicies($Item.Path, $Policies);
}
}In above script i have few questions like below:
a. ReportServiceUri could be same or i have to edit some thing here.
b. GroupUserName: I have to use like as per my organization : <Organization>/UserName
If that is the case then like in ReportServer > SiteSettings > Security when i add new user then when i type the new user mail id that is automatically fetch the related User in above format and set. Can i do the same here also?
c. This complete script can i run through web application?
Please suggest on above.
Hi Team,
Kindly provide and update on above asked. We need urgent fix for this issue.