Automation

 View Only
  • 1.  powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 01:44 PM

    I need to download a txt file from multiple vm folders on multiple datastores. 

     

    Is there a script to do this?



  • 2.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 01:59 PM

    You could do something like this.

    - the script copies the files to a Temp folder, but you can change the destination via the $tgtFolder variable
    - note that the filename (in $txtFileName) is case sensitive
    - if not all VM shall be used, the Get-VM at the beginning can be adapted

     



  • 3.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 02:24 PM

    Thanks Luc

     

    what does 

     

    do ?

    I want to get all a list of vms in csv file

     

    Name
    vm1
    vm2

     

    The download the vmname.vmsn file



  • 4.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 02:48 PM

    i tried this but it did not download the vmsn file

     

    $txtFileName = 'vmname.vmsn'

    $tgtFolder = $env:Temp
    $vm = get-vm -name vmname

    Get-VM $vm |
    ForEach-Object -Process {
    $dsName = ($vm.ExtensionData.Config.Files.VmPathName.Split())[0]
    $dsName = $dsName.Trim('[]')
    $ds = Get-Datastore -Name $dsName
    New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
    Copy-DatastoreItem -Item "DS:$($vm.Name)/$txtFileName" -Destination "$($tgtFolder)\$($vm.Name)-$txtFileName"
    Remove-PSDrive -Name DS -Confirm:$false
    }



  • 5.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 03:06 PM

    ok I got wrong variable. never mind. Thanks lucd



  • 6.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 03:49 PM

    is there way to modify this t grab only the vmsn file from my csv file of vms?



  • 7.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 03:56 PM

    Sure, something like this



  • 8.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 04:32 PM

    for the vmsn file name I tried using

     

    $vm = Get-VM -Name $vmName

    $snap = Get-Snapshot -VM $vm -Name $snapName

    ($vm.ExtensionData.Layout.Snapshot | where{$_.Key -eq $snap.ExtensionData.Snapshot}).SnapShotFile | where{$_ -match ".vmsn$"}

     

    how do I trim the output to show only the vmsn file and not the full datastore path/vmsn file

     

    thanks



  • 9.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 04:37 PM

    You mean <Vm name>.vmsn?



  • 10.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 04:37 PM

    yes



  • 11.  RE: powercli to download single .txt file from multiple vm folders

    Posted Sep 09, 2022 04:42 PM

    Try with