Trying to automate a PS Script

Welcome Forums General PowerShell Q&A Trying to automate a PS Script

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #85184

    Points: 0
    Rank: Member

    Hey Folks!

    We're having issues with orphaned snapshots being left behind on failed Hyper-V backups. The script I run to delete the old snaps is fairly straightforward:

    Get-VMSnapshot -VMName VMNAME | Remove-VMSnapshot

    Doing this is fairly quick, but I figured I could automate this if I put a little more effort in. Here's what I have so far.

    If I run the following script on the Hyper-V Host I get a nice little CSV file with the names that would be the "VMNAME" above:

    Get-VM | Select-Object Name | Export-CSV PATH -NoTypeInformation

    It's here that I'm struggling to read the CSV file and populate the "VMNAME" portion from the CSV file? Any help would be greatly appreciated!


  • #85187

    Points: 77
    Rank: Member

    Something like this maybe (caveat I don't know all the hyper v cmdlets or what your csv looks like), assuming your csv has name at the top and all the vm name's below it

    import-csv C:\servers.csv | % {Get-VMSnapshot -VMName $ | Remove-VMSnapshot}

    or this might work (see above caveat)

    Get-vm | get-vmsnapshot | remove-vmsnapshot
    • #85190

      Points: 0
      Rank: Member

      Hi Jon,

      The first script worked perfectly, thanks!


The topic ‘Trying to automate a PS Script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort