I have two datastores, datastore-old and datastore-new, mounted across my environment.
I believe I've copied the files from datastore-old to datastore-new, however as a check I'd like to obtain two exports. One for datastore-old and the other for datastore-new with column headers:
Datastore Folder | Child FileName | Child File Size | Child File Modified Date| Child File Path
I will then do a match in Excel to verify the contents of datastore-new matches datastore-old.
How do I get this? My thanks in advance for assistance.
You can use the Compare-Object cmdlet to compare two arrays.
Getting the files from both datastores can be done with the vimdatastore provider.
$dsOldName = 'datastore1'
$dsNewName = 'datastore2'
$dsOld = Get-Datastore -Name $dsOldName
$dsNew = Get-Datastore -Name $dsNewName
New-PSDrive -Location $dsOld -Name OLD -PSProvider VimDatastore -Root '\' | Out-Null
New-PSDrive -Location $dsNew -Name NEW -PSProvider VimDatastore -Root '\' | Out-Null
$oldFiles = Get-ChildItem -Path OLD: -Recurse | Select -ExpandProperty DatastoreFullPath
$newFiles = Get-ChildItem -Path NEW: -Recurse | Select -ExpandProperty DatastoreFullPath
Remove-PSDrive -Name OLD -Confirm:$false
Remove-PSDrive -Name NEW -Confirm:$false
Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
To export to a CSV you have to use
Get-ChildItem -Path OLD: -Recurse | Select -Property DatastoreFullPath |
Export-Csv -Path .\oldfiles.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the Compare-Object cmdlet to compare two arrays.
Getting the files from both datastores can be done with the vimdatastore provider.
$dsOldName = 'datastore1'
$dsNewName = 'datastore2'
$dsOld = Get-Datastore -Name $dsOldName
$dsNew = Get-Datastore -Name $dsNewName
New-PSDrive -Location $dsOld -Name OLD -PSProvider VimDatastore -Root '\' | Out-Null
New-PSDrive -Location $dsNew -Name NEW -PSProvider VimDatastore -Root '\' | Out-Null
$oldFiles = Get-ChildItem -Path OLD: -Recurse | Select -ExpandProperty DatastoreFullPath
$newFiles = Get-ChildItem -Path NEW: -Recurse | Select -ExpandProperty DatastoreFullPath
Remove-PSDrive -Name OLD -Confirm:$false
Remove-PSDrive -Name NEW -Confirm:$false
Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucDthis is great, however, the syntax as you had it scrolls the results on screen and I can't analyze the output.I also had to insert a Get-Cluster request before the get-datastore due to how our env is set up.
I exported $oldFiles and $newFiles to csv and the csv files contained one column titled Length.
$dsOldName = 'olddatastore'
$dsNewName = 'newdatastore'
$dsOld = Get-Cluster 'clusterName' | Get-Datastore -Name $dsOldName
$dsNew = Get-Cluster 'clusterName' |Get-Datastore -Name $dsNewName
New-PSDrive -Location $dsOld -Name OLD -PSProvider VimDatastore -Root '\' | Out-Null
New-PSDrive -Location $dsNew -Name NEW -PSProvider VimDatastore -Root '\' | Out-Null
$oldFiles = Get-ChildItem -Path OLD: -Recurse | Select -ExpandProperty DatastoreFullPath
$newFiles = Get-ChildItem -Path NEW: -Recurse | Select -ExpandProperty DatastoreFullPath
Remove-PSDrive -Name OLD -Confirm:$false
Remove-PSDrive -Name NEW -Confirm:$false
Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles
The output looked similar to:
[oldDatastore] ISOs/vmware/co/rhel-atomic-cloud-7.3.1-1.x86_64.vsphere.ova
[oldDatastore ISOs/vmware/co/test.txt
[oldDatastore] ISOs/vmware/6.5/Cisco/VMware-ESXi-6.5.0-9298722-Custom-Cisco-6.5.2.2-Bundle.zip
[oldDatastore] ISOs/vmware/6.5/Cisco/VMW-ESX-6.5.0-nenic-1.0.29.0-offline_bundle-12982103.zip
[oldDatastore] ISOs/vmware/6.5/Cisco/Vmware-ESXi-6.5.0-7967591-Custom-Cisco-6.5.1.3-Update1.zip
[oldDatastore] ISOs/vmware/6.5/Cisco/VMW-ESX-6.5.0-nenic-1.0.33.0-offline_bundle-16182785.zip
[oldDatastore] ISOs/vmware/6.5/Cisco/VMware_ESXi_6.5.0_13932383_Custom_Cisco_6.5.3.1_Bundle.zip
[oldDatastore] template_rhel_7_6_20181220_vc010no_cgno/template_rhel_7_6_20181220_vc010no_cgno.vmsd
[oldDatastore] template_rhel_7_6_20181220_vc010no_cgno/template_rhel_7_6_20181220_vc010no_cgno.vmxf
[oldDatastore] template_rhel_7_6_20181220_vc010no_cgno/template_rhel_7_6_20181220_vc010no_cgno-214612ff.hlog
[oldDatastore ISOs/netcracker/Netcracker-nc1.ova
[oldDatastore ISOs/Davra/coreos_production_vmware_ova_10.ova
Great information, just a question. In the way the data is presented, is ISOs most likely my folder name (I believe it is)? Also, when I see this go zipping by on screen does that mean that these particular files are on oldDatastore and not on newDatastore, similar to a unix sdiff suppress duplicate files? It has to do something with invoking out-grid-view but as always, Luc, I need a little coaching.
To export to a CSV you have to use
Get-ChildItem -Path OLD: -Recurse | Select -Property DatastoreFullPath |
Export-Csv -Path .\oldfiles.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI C:\> Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles | Out-GridView -PassThru | Clip
With out-gridview open, I selected CTRL-A (select all), then CTRL-C (copy), ok, and pasted into Excel. All good now. Thanks @LucD