Sql server PowerShell/SQL脚本自动化-作业SQL报表服务器
这是我发现的一段代码,用于在SQL report server环境中的每个文件夹中添加或删除单个广告帐户/组。我是新手,有没有人可以给我解释一下代码。谢谢Sql server PowerShell/SQL脚本自动化-作业SQL报表服务器,sql-server,powershell,reporting-services,ssis,Sql Server,Powershell,Reporting Services,Ssis,这是我发现的一段代码,用于在SQL report server环境中的每个文件夹中添加或删除单个广告帐户/组。我是新手,有没有人可以给我解释一下代码。谢谢 Clear-Host $ReportServerUri = 'http://PorteousSQL1/ReportServer/ReportService2010.asmx?wsdl' $InheritParent = $true $GroupUserName = 'Domain\Deploy' $RoleName = 'Publisher'
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);
}
}