question

Cataster-7485 avatar image
0 Votes"
Cataster-7485 asked CarrinWu-MSFT edited

How to rename SSAS/Tabular cube in Powershell?

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?




windows-server-powershellsql-server-analysis-services
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Hi @Cataster-7485, could you please do "Accept Answer" if below anwsers help you? By doing so, it will benefit for community members who have this similar issue. Your contribution is highly appreciated. Thank you!

0 Votes 0 ·
DarrenGosbell-0123 avatar image
0 Votes"
DarrenGosbell-0123 answered

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()

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CarrinWu-MSFT avatar image
0 Votes"
CarrinWu-MSFT answered DarrenGosbell-0123 edited

Hi @Cataster-7485,

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@CarrinWu-MSFT Thanks for the welcome Carrin. Is there a TMSL reference/example you can provide for altering both the Name AND ID of a Cube?

0 Votes 0 ·

As I mentioned in our other thread. You cannot alter the ID property of an object


0 Votes 0 ·

Even in TMSL?

0 Votes 0 ·
Show more comments