life4dummies
Contributor
Contributor

I realize my first mistake. I thought that $tgtFolder would be the datastore that the VM(s) resided on.

Now that I have corrected that, i'm getting two different errors that you see below.

Copy-DatastoreItem : 11/14/2019 2:32:12 PM VimDatastore Download of file

'https://phdvc01/folder%2fdpacsorat01%2fdpacsorat01.vmx?dcPath=DBD+DC&dsName=dxi0827_tst_cl2_lun017' failed. Error message: The

remote server returned an error: (404) Not Found.

At line:10 char:3

+   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], VimException

    + FullyQualifiedErrorId : Client20_StorageServiceImpl_DownloadFile_DownloadFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.C

   opyDatastoreItem

Copy-DatastoreItem : Object reference not set to an instance of an object.

At line:10 char:3

+   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], NullReferenceException

    + FullyQualifiedErrorId : System.NullReferenceException,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyDatastoreItem

Full script is below. All I did was change $tgtFolder, $tgtString, and I specified a single VM as to not run it against the entire environment (yet)

$vmName = "dpacsorat02"

$tgtFolder = "D:\TEMP\VMX\"

$tgtString = 'sound.virtualDev = "hdaudio"'

Get-VM -Name $vmName | %{

  $dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()

  $dsName = $dsName.Trim('[]')

  $ds = Get-Datastore -Name $dsName

  New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null

  Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

  Remove-PSDrive -Name DS -Confirm:$false

}

Get-ChildItem -Path $tgtFolder -Filter "*.vmx" |

Where {Get-Content -Path $_.FullName | Select-String -Pattern $tgtString} |

Select Name

Reply
0 Kudos