my goal is to do bulk deletion of SSRS reports but not all of them .
ONLY reports from the $xnames
should be deleted, rest of reports should stay without any changes.
Something like below:
$xnames = @("AAA4201_Report","AAA9999_XReport","QQQ1000_Report")
Get-RsCatalogItems -ReportServerUri $TargetReportServerUri -RsFolder '/AA' |
# only if Report_Name in $xnames # ?????? |
Remove-RsCatalogItem -ReportServerUri $TargetReportServerUri
#### output of Get-RsCatalogItems
ID : ad347c46-51a8-4934-961c-b6d976f85aa9
Name : AAA4201_Report
Path : /AA/AAA4201_Report
VirtualPath :
...........
...........
#### Prompt after Remove-RsCatalogItem
Confirm
Are you sure you want to perform this action?
Performing the operation "Delete the catalog item" on target
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1Reports_ReportService2010_asmx.CatalogItem".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
### Parameter list of Remove-RsCatalogItem function
param (
[Alias('ItemPath', 'Path')]
[Parameter(Mandatory = $True, ValueFromPipeline = $true)]
[ System.Object[] ]
$RsFolder,
[string]
$ReportServerUri,
[Alias('ReportServerCredentials')]
[System.Management.Automation.PSCredential]
$Credential,
$Proxy
)
Alternatively I tried to use Remove-RsCatalogItem
without RSGetCatalogItems
, but it doesn't work. Is this possible. I can add url portion to report name out of $xnames
and loop thru this list.
Even without any confirmation.
Something like:
Remove-RsCatalogItem -ReportServerUri $TargetReportServerUri -ReportURI(?) $xReportURL
You're looking to filter the catalog items by whether their names are contained in an array of given names ($xnames
), which you can do with Where-Object
:
Get-RsCatalogItems -ReportServerUri $TargetReportServerUri -RsFolder /AA |
Where-Object Name -in $xnames |
Remove-RsCatalogItem -ReportServerUri $TargetReportServerUri -WhatIf
Note:
The -WhatIf
common parameter in the command above previews the operation. Remove -WhatIf
and re-execute once you're sure the operation will do what you want.
If you want to avoid a confirmation prompt, add -Confirm:$false
.
The above Where-Object
call uses simplified syntax in; it is the equivalent of:
Where-Object { $_.Name -in $xnames }