Automation

 View Only
  • 1.  Get contents from within the square brackets

    Posted 11 days ago

    Hello,

    Hopefully this is an easy question:

    I need to get a datastore name from within the square brackets of a field of an array:

    $vm.datastorefullpath = [IOMEGA_lun01] myvm-new-1/myvm-new-1.vmx

    Trying to get the datastore name so I can use it here:
    Get-Datastore -Name ???

    Thanks!



  • 2.  RE: Get contents from within the square brackets

    Posted 11 days ago

    Did you try with single quotes?

    $vm.datastorefullpath = '[IOMEGA_lun01] myvm-new-1/myvm-new-1.vmx'


    ------------------------------


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


    ------------------------------



  • 3.  RE: Get contents from within the square brackets
    Best Answer

    Posted 10 days ago

    If want to extract the datastore name then try as below

    $DatastoreName = ($vm.datastorefullpath -split '\s')[0].Trim('[]')
    Write-Output $DatastoreName




  • 4.  RE: Get contents from within the square brackets

    Posted 10 days ago

    Yes, that's what I need, sorry for the poorly worded question.

    Thanks!