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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
$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
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Hello Lucd,
I would think the vm should be shutdown prior to running this script?
Thoughts?
Norm
Depends what file needs to be renamed, but yes, powering it off would be on the safe side.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
I forgot the add the file extension to the new name.
Can you try with this updated version?
$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
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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,