Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
Gartner® Magic Quadrant™: 15 YEARS A LEADER - GET THE REPORT
cancel
Showing results for 
Search instead for 
Did you mean: 
Raju_6952
Creator III
Creator III

Power shell scripting to delete multiple bookmarks owned by users

Hi,

I am planning to below power shell scripting to delete the bookmark owned by specific users and that are never published.

Is this code finde or need to make any changes here.

# Define your Qlik server, app ID, and credentials

$qlikServer = "https://<QlikServer>:4242"

$appId = "<YourAppID>"

$headers = @{

    "X-Qlik-User" = "UserDirectory=Internal;UserId=sa_repository"

}

 

# Define a list of specific owners (usernames) whose unpublished bookmarks should be deleted

$specificOwners = @("user1", "user2", "user3") # replace with actual usernames

 

# Step 1: Get all bookmarks in the app

$bookmarks = Invoke-RestMethod -Uri "$qlikServer/qrs/bookmark/full?filter=app.id eq '$appId'" -Headers $headers -Method Get

 

# Step 2: Loop through bookmarks and delete only unpublished (never published) bookmarks from specific owners

foreach ($bookmark in $bookmarks) {

    # Check if the bookmark is unpublished (no publishTime and published is false) and the owner is in the specified list

    if (-not $bookmark.publishTime -and !$bookmark.published -and $specificOwners -contains $bookmark.owner.userId) {

        # Delete the unpublished bookmark

        $bookmarkId = $bookmark.id

        Invoke-RestMethod -Uri "$qlikServer/qrs/bookmark/$bookmarkId" -Headers $headers -Method Delete

        Write-Output "Deleted unpublished bookmark with ID: $bookmarkId, owned by $($bookmark.owner.userId)"

    }

}

 

Any suggestions would be highly appreciated.

 

Regards,

Raju

Labels (3)
1 Solution

Accepted Solutions
Marc
Employee
Employee

if you are just deleting the app objects from the QRS, you can use the QlikSenseCLI in the tools folder

Import-Module 'C:\Program Files\Qlik\Sense\Tools\QlikSenseCLI\QlikSenseCLI.psd1'
Connect-QlikSense
$specificOwners = @("user1", "user2", "user3") # replace with actual usernames
$appId = 'AppGuid'

$QSBookmarks = Get-QSAppObject -Filter "app.id eq $($appId) and ObjectType eq 'bookmark' and ($(($specificOwners|%{"Owner.userid eq '$_'"}) -join(" or ")))"

foreach($QSBookmark in $QSBookmarks){
Remove-QSAppObject -Id $QSBookmark.id
}

View solution in original post

3 Replies
Marc
Employee
Employee

This will only remove the bookmarks from the QRS (Metadata), they will still exist in the App Binary file.
to remove them from the binary, you need to use the engine APIs to remove the Bookmarks from the app.

e.g. Qlik Sense SDK,

You will need a process similar to the one outlined here: Exporting-Qlik-Script-QVS-with-Powershell-QSefW to get the $QEApp so you can call DestroyGenericBookmark with the Bookmark Engine ObjectID
$QEApp.DestroyGenericBookmark($bookmark.EngineObjectID)

Raju_6952
Creator III
Creator III
Author

Hi @Marc ,

 

We got some python script which can be used to delete the bookmarks from app binary by listening the bookmarks object ifs in the CSV file .

 

Regards,

Raju

Marc
Employee
Employee

if you are just deleting the app objects from the QRS, you can use the QlikSenseCLI in the tools folder

Import-Module 'C:\Program Files\Qlik\Sense\Tools\QlikSenseCLI\QlikSenseCLI.psd1'
Connect-QlikSense
$specificOwners = @("user1", "user2", "user3") # replace with actual usernames
$appId = 'AppGuid'

$QSBookmarks = Get-QSAppObject -Filter "app.id eq $($appId) and ObjectType eq 'bookmark' and ($(($specificOwners|%{"Owner.userid eq '$_'"}) -join(" or ")))"

foreach($QSBookmark in $QSBookmarks){
Remove-QSAppObject -Id $QSBookmark.id
}