Automation

 View Only
  • 1.  Set-Datastore -Name not working

    Posted May 02, 2023 05:56 PM

    What should be a simple one liner is driving me insane.

    I am trying to rename a datastore on a new host via PowerCLI.

    $IPAddress = [host IP address]
    $HostName = [host name]
    $ESXiHost = Get-VMHost $IPAddress
    $DefaultDatastoreName = ($ESXiHost | Get-Datastore | where {$_.capacityGB -like "*95*"}).Name
    $NewOSDatastoreName = $HostName+"_os"
    $ESXIHost | Get-Datastore -Name $DefaultDatastoreName | Set-Datastore -Name $NewOSDatastoreName -Confirm:$False
     
    I have confirmed each of these individual variables yields the correct object/string. I have tried eliminating variables by feeding in explicit strings.
    No matter what I do, whenever I run the final line, it just returns the current datastore name:
     
    Name FreeSpaceGB CapacityGB
    ---- ----------- ----------
    temp_name 93.844 95.250
     
    Please help!


  • 2.  RE: Set-Datastore -Name not working
    Best Answer

    Posted May 02, 2023 09:07 PM

    Are you connected to a vCenter or an ESXi node?
    If that datastore is managed by a vCenter, you can't do the rename when connected to the ESXi node.
    You have to be connected to the vCenter

    I just tested that, and I see the same behavior you are seeing.
    The Set-Datastore cmdlet might return some more info on the why.

    From the ESXi Host Client you'll notice that the Rename Action is greyed out.



  • 3.  RE: Set-Datastore -Name not working

    Posted May 03, 2023 12:49 PM

    Perfect! Thank you!