How to rename SSAS/Tabular cube in Powershell?

Cataster 641 Reputation points
2021-07-19T19:35:12.64+00:00

I am trying to rename a cube using Rename-Item but it doesn't work, with the following error returned:

Here is my code:

Import-Module SqlServer
$Analysis_Server = New-Object Microsoft.AnalysisServices.Server
$Analysis_Server.connect("server1")
$cube_name = $Analysis_Server.Databases.FindByName("Snapshot-4")
$cube_name | Rename-Item -NewName ("Snapshot-xy")

error:

Rename-Item : Illegal characters in path.
Rename-Item : Cannot rename because item at '<DatabaseID>Snapshot-4</DatabaseID>' does not
exist.

The database most certainly exists. I verified the ID matches as well using $cube_name.ID

Is it not possible to rename a cube in powershell?

SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,242 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,351 questions
{count} votes

Accepted answer
  1. Darren Gosbell 1,466 Reputation points
    2021-07-19T23:36:30.94+00:00

    So rename-item works with objects that support the PSDrive interface which the SSAS database does not support natively. The FindByName method on the Databases collection returns a database object, you can just change the Name property and then call the Update method to persist this change back to the server.

    eg.

    Import-Module SqlServer
    $Analysis_Server = New-Object Microsoft.AnalysisServices.Server
    $Analysis_Server.connect("server1")
    $db = $Analysis_Server.Databases.FindByName("Snapshot-4")
    $db.name = "Snapshot-xy"
    $db.Update()

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. CarrinWu-MSFT 6,851 Reputation points
    2021-07-20T03:27:34.717+00:00

    Hi @Cataster ,

    Welcome to Microsoft Q&A!

    Sorry about that I just work with SSAS and not familiar with PowerShell. I hope below links can help you:
    Alter command (TMSL)
    Renaming an SSAS Tabular Model

    Best regards,
    Carrin


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.