PowerCLI

 View Only
Expand all | Collapse all

RVTools health message Inconsistent folder name

  • 1.  RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 05:43 PM

    Good morning experts

    Is there a way via powercli to fix the problem of inconsistent folder names?

    Thank you for any and all input!!

    Norm



  • 2.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 06:30 PM

    What exactly do you mean by inconsistent folder names?

    Perhaps you better contact Rob himself (he has a Contact form on the RVTools website).
    He is very responsive to feedback.



  • 3.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 06:45 PM

    Hello Lucd,

    Here is a snippet of output from rvtools.

    And now a snippet from vsphere  -- The vm file names have a lower w while the actual name is uses a upper case W

    Norm



  • 4.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 07:30 PM

    Ok, got it.
    Try something like this.
    First try with 1 datastore and 1 VM.

    Only remove the WhatIf when you are absolutely sure it is renaming the correct files with the correct name

    $dsName = 'MyDS'

    $ds = Get-Datastore -Name $dsName


    Get-VM -Name MyVM -PipelineVariable vm |

    ForEach-Object -Process {

       $path = $vm.ExtensionData.Summary.Config.VmPathName.Split('/')[0]

       $folder = $path.Split(' ')[1]

       $dsName = $folder.Split(' ')[0].Trim('[]')

       New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '/' | Out-Null

       Get-ChildItem -Path "DS:/$folder" |

       Where-Object { $_.Name -notmatch "^\." -and $_.Name.Split('.')[0].Split('-')[0].Split('_')[0] -cne $vm.Name } |

       ForEach-Object -Process {

       Write-Host "For VM $($vm.Name) the file $($_.Name) is inconsisten"

       Rename-Item -Path "DS:\$folder\$($_.Name)" -NewName $vm.Name -WhatIf

       }

       Remove-PSDrive -Name DS -Confirm:$false

    }



  • 5.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 08:11 PM

    Hello Lucd,

    Did a dry run,  output looks good to me.  Waiting for our vmware admin to respond to my email before I remove the whatif.

    As always thank you.

    Norm



  • 6.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 08:13 PM

    Hello Lucd,

    I would think the vm should be shutdown prior to running this script?

    Thoughts?

    Norm



  • 7.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 08:15 PM

    Depends what file needs to be renamed, but yes, powering it off would be on the safe side.



  • 8.  RE: RVTools health message Inconsistent folder name

    Posted Apr 18, 2019 08:18 PM

    Come to think of it, I'm not sure if it tackles a VMDK correctly (since those 2 files and the header contains pointers).
    Best try that first with a test VM.



  • 9.  RE: RVTools health message Inconsistent folder name

    Posted Apr 29, 2019 11:32 PM

    Hello Lucd,

    Back from vacation, ran the script here's what i got

    NOTE: CHANGED THE NAME OF THE VM FROM  TL-FWAppcent to TL-FWAppcent-test in vsphere.  The script had some issues.

    Please note the attached document which contains all the output and green shots of what I'm seeing in vsphere, any advice has to how to proceed?  This is over my feeble mind.



  • 10.  RE: RVTools health message Inconsistent folder name

    Posted Apr 29, 2019 11:57 PM

    I forgot the add the file extension to the new name.

    Can you try with this updated version?

    $dsName = 'MyDS'

    $ds = Get-Datastore -Name $dsName


    Get-VM -Name MyVM -PipelineVariable vm |

    ForEach-Object -Process {

       $path = $vm.ExtensionData.Summary.Config.VmPathName.Split('/')[0]

       $folder = $path.Split(' ')[1]

       $dsName = $folder.Split(' ')[0].Trim('[]')

       New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '/' | Out-Null

       Get-ChildItem -Path "DS:/$folder" |

       Where-Object { $_.Name -notmatch "^\." -and $_.Name.Split('.')[0].Split('-')[0].Split('_')[0] -cne $vm.Name } |

       ForEach-Object -Process {

         Write-Host "For VM $($vm.Name) the file $($_.Name) is inconsisten"

         $ext = $_.Name.Split('.')[-1]

         Rename-Item -Path "DS:\$folder\$($_.Name)" -NewName "$($vm.Name).$($ext)" -WhatIf

       }

       Remove-PSDrive -Name DS -Confirm:$false

    }



  • 11.  RE: RVTools health message Inconsistent folder name

    Posted Apr 30, 2019 04:17 PM

    Hello Lucd,

    Well were a step closer, the script did not change one of the files nor the master folder.  I was able to change the folder name  and the one file name, attempted to restart the vm but was unable to.  The attached word doc has all the info.

    Thank you for your help

    Norm



  • 12.  RE: RVTools health message Inconsistent folder name

    Posted Apr 30, 2019 07:34 PM

    The script doesn't rename the folder itself.

    The VMDK pose indeed an issue (as I already suspected earlier),since they in fact consist of 2 separate files, the header file and a file with the data.

    A correct rename of a VMDK seems to require the use of vmkfstools.
    Since you can't call vmkfstools directly from a PowerCLI script, I'm afraid this process can't be done in a pure PCLI script.
    You could call the vmkfstools command through a SSH session.



  • 13.  RE: RVTools health message Inconsistent folder name

    Posted May 01, 2019 04:28 PM

    The best way I have found to fix inconsistent folder names is to simply do a storage vmotion - assuming you are licensed for it.    the storage vmotion will "fix" the foldername and vmdk filenames to match the vm name.

    Regards,