VMware Cloud Community
dinny
Expert
Expert
Jump to solution

Problem renaming local datastore with set-datastore cmdlet

Hiya,

I've just started using powercli to configure my ESX 4.1i servers.

Most of my build script works fine - but I can't seem to rename the local datastore.

I do a get-datastore based on the name which works fine, I then pipe it to set-datastore with a new name - but it just seems to ignore the command and leave it with the old name.

No error messages are produced.

I've pasted in the results of the "get-datastore" (just to show that it does exist) and the results of the "get-datastore piped to set-datastore", below.

I'm sure I'm missing something really obvious - but I'm not sure what?

[vSphere PowerCLI] D:\powershell> get-datastore -name "test1" | fl


DatacenterId         : Datacenter-ha-datacenter
Datacenter           : ha-datacenter
ParentFolderId       : Folder-ha-folder-datastore
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\ohst213vmh.blah.co.uk@443\ha-datacenter\test1
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-4d4c2877-c48e1465-b0be-00237d358458
Name                 : test1
Uid                  : /VIServer=root@ohst213vmh.blah.co.uk:443/Datastore=Datastore-4d4c2877-c48e1465-b0be-002
                       37d358458/

[vSphere PowerCLI] D:\powershell> get-datastore -name "test1" | set-datastore -name "test2" | fl


DatacenterId         : Datacenter-ha-datacenter
Datacenter           : ha-datacenter
ParentFolderId       : Folder-ha-folder-datastore
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\ohst213vmh.blah.co.uk@443\ha-datacenter\test1
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-4d4c2877-c48e1465-b0be-00237d358458
Name                 : test1
Uid                  : /VIServer=root@ohst213vmh.blah.co.uk:443/Datastore=Datastore-4d4c2877-c48e1465-b0be-002
                       37d358458/

Cheers

Dinny

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you add an ESX server to vCenter, the VirtualCenter agent service (vpxa) is installed on the ESX server.

All actions you take on the ESX server in the vSphere client or in a PowerCLI script while connected to the vCenter, are passed through this vpxa service. This service controls the resources on the ESX server.

To avoid problems when you would change some resources directly from the ESX COS, the vpxa services locks these resources.

That's why you can't change the datastorename while connected directly to an ESX server that has been added to a vCenter.

Btw if you connect a vSphere client directly to the ESX server, you will see the same phenomena as what you are seeing in your PowerCLI script.

If you need to change the datastorename locally on the ESX for whatever reason, you could try removing the ESX server with Remove-VMHost from vCenter, connect to the ESX server with Connect-VIServer, make your changes and add it back to the vCenter with Add-VMHost.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
11 Replies
alefestaedist
Hot Shot
Hot Shot
Jump to solution

Did you try the same  command   with the -Name with the capital letter. Seems PowerCli is case sensitve in some cases.

Set-Datastore [-Datastore] <Datastore> [-Name] <String> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Just tried with -Name - no difference unfortunately..

Thanks

Dinny

Reply
0 Kudos
alefestaedist
Hot Shot
Hot Shot
Jump to solution

Just tried on my lab and your command it works so I assume could be a permission problem, where is the datastore? it is a shared between host or it is a local datastore? so in either case are you connecting to Vcenter or directly to host?

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Hiya,

It is a local datastore.

The server is in VC, but I am connecting directly to the ESX server via the root id (as I am for the rest of the script which seems to work OK)

I'll try via VC...

Dinny

Reply
0 Kudos
alefestaedist
Hot Shot
Hot Shot
Jump to solution

I agree that sounds weird I've don the same connecting both to host and VC and your command is correct. I would try to rename the datastore from the  GUI connecting directly to the host throught the vSphere client, just to check if the issue is related to powercli only or is it something else.

Alex

dinny
Expert
Expert
Jump to solution

I did initially rename the datastore from datastore (1) to test1 via the GUI.

Now I'm really confused...

I connected via VC and then via get-vmhost

I then did a get-datastore -name "test1" and it picked up two different datastores (I suspect two views of the same datastore?)

However - the rename did then work (seemingly twice.. - see below)

Does anyone have any idea why it might fail when connecting directly to the ESX server? - as that is how the rest of my build script is designed to work.

So I would really like to get it working in that context.

[vSphere PowerCLI] D:\powershell> get-datastore -Name "test1" | fl


DatacenterId         : Datacenter-datacenter-2
Datacenter           : ESX 4
ParentFolderId       : Folder-group-s4306
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\spek060svr.blah@443\ESX 4\test1
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-datastore-7878
Name                 : test1
Uid                  : /VIServer=gtsg043@spek060svr.blah:443/Datastore=Datastore-datastore-7878/

DatacenterId         : Datacenter-ha-datacenter
Datacenter           : ha-datacenter
ParentFolderId       : Folder-ha-folder-datastore
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\ohst213vmh.blah@443\ha-datacenter\test1
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-4d4c2877-c48e1465-b0be-00237d358458
Name                 : test1
Uid                  : /VIServer=root@ohst213vmh.blah:443/Datastore=Datastore-4d4c2877-c48e1465-b0be-002
                       37d358458/

[vSphere PowerCLI] D:\powershell> get-datastore -Name "test1" | set-datastore -Name "test2" | fl


DatacenterId         : Datacenter-datacenter-2
Datacenter           : ESX 4
ParentFolderId       : Folder-group-s4306
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\spek060svr.blah@443\ESX 4\test2
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-datastore-7878
Name                 : test2
Uid                  : /VIServer=gtsg043@spek060svr.blah:443/Datastore=Datastore-datastore-7878/

DatacenterId         : Datacenter-ha-datacenter
Datacenter           : ha-datacenter
ParentFolderId       : Folder-ha-folder-datastore
ParentFolder         : datastore
DatastoreBrowserPath : vmstores:\ohst213vmh.blah@443\ha-datacenter\test1
FreeSpaceMB          : 64207
CapacityMB           : 64768
Accessible           : True
Type                 : VMFS
ExtensionData        : VMware.Vim.Datastore
Id                   : Datastore-4d4c2877-c48e1465-b0be-00237d358458
Name                 : test1
Uid                  : /VIServer=root@ohst213vmh.blah:443/Datastore=Datastore-4d4c2877-c48e1465-b0be-002
                       37d358458/

[vSphere PowerCLI] D:\powershell>

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The fact that you see 2 datastore objects could be because you have 2 connections open and you use multi-server mode.

Check with

Get-PowerCLIConfiguration

$defaultVIServers.

Can you perhaps also do a Get-VIPermission in both cases (connected to VC and connected to ESX) ?

     Get-VIPermission -Entity (Get-Datastore -Name "test1")

And is your ESX server set up for AD authentication or do you use local users ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

dinny
Expert
Expert
Jump to solution

Hi LucD,

You were of course completely correct re me having two open connections (I had thought that I'd closed the other - clearly not!)

Re the permissions - they both seem to have admin rights - see below:

My server is not set up for AD - it just uses local users.

Via VC - logged on as gts...

[vSphere PowerCLI] D:\powershell> Get-VIPermission -Entity (Get-Datastore -Name "test5")

EntityId             Role                      Principal       IsGroup Propagate
--------             ----                      ---------       ------- ---------
Folder-group-d1      Admin                     vm?????         False   True
Folder-group-d1      Admin                     blah\rp... False   True
Folder-group-d1      Admin                     blah\lts... False   True
Folder-group-d1      Admin                     blah\gts... False   True
Folder-group-d1      VCB - Netbackup restores  blah\vcb... False   True
Folder-group-d1      ReadOnly                  blah\ita... False   True
Folder-group-d1      VirtualMachineAdminist... blah\g-I... True    True

via ESX - logged on as root

[vSphere PowerCLI] D:\powershell> Get-VIPermission -Entity (Get-Datastore -Name "test5")

EntityId             Role                      Principal       IsGroup Propagate
--------             ----                      ---------       ------- ---------
Folder-ha-folder-... Admin                     vpxuser         False   True
Folder-ha-folder-... Admin                     dcui            False   True
Folder-ha-folder-... Admin                     root            False   True

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

I have just tried the commands on two new ESX servers that I only configured today - neither have been added to VC before.

(as I wondered if the server that I had initially been testing on was corrupt or non-standard in some way)

On the first I ran the script via the ESX server as root - it worked fine.

(the server was not, and never had been managed by VC)

On the second, I added it to VC first, then I ran the script via the ESX server as root - it failed.

So it does seem as though being managed by VC (at least in my env) is causing the set-datastore command to fail when connecting via ESX as root for some reason.

Intriguing...

Dinny

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you add an ESX server to vCenter, the VirtualCenter agent service (vpxa) is installed on the ESX server.

All actions you take on the ESX server in the vSphere client or in a PowerCLI script while connected to the vCenter, are passed through this vpxa service. This service controls the resources on the ESX server.

To avoid problems when you would change some resources directly from the ESX COS, the vpxa services locks these resources.

That's why you can't change the datastorename while connected directly to an ESX server that has been added to a vCenter.

Btw if you connect a vSphere client directly to the ESX server, you will see the same phenomena as what you are seeing in your PowerCLI script.

If you need to change the datastorename locally on the ESX for whatever reason, you could try removing the ESX server with Remove-VMHost from vCenter, connect to the ESX server with Connect-VIServer, make your changes and add it back to the vCenter with Add-VMHost.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Ah well,

I guess that is logical - strange that all the other stuff in my sript worked OK - but I guess they were mainly creates as opposed to amends.

Guess I'll just have to remember to always run the script prior to adding the server to VC

Thanks for all the help/suggestions.

Cheers

Dinny

Reply
0 Kudos