0

I was trying to edit the description field of all snaps present in vcenter. The script is able to find the snaps properly and its trying to edit the same, i could see the task as renaming snapshot, but not reflecting the change actually. Can some somebody help me resolve this.. ? Thanks in advance.

   Get-Module -Name VMware* -ListAvailable | Import-Module
$AllSnaps = @()
$User = "Domain\UserName"
$File = "Credentials.txt"
$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)

foreach ($VC in $VCServers) {

$Stat = connect-viserver $VC -credential $MyCredential -erroraction 'silentlycontinue'
     if($Stat.IsConnected){
            write-host "Connected to VC - $VC"
            $AllSnaps = Get-VM  | Get-Snapshot | select VM, Name, Description
                 ForEach ($Snap in $AllSnaps)  {
                      If ($($Snap.Name) -Match "NBU_SNAPSHOT" -or $($Snap.Description) -Match "PERM-") {
                      Write-host "No Action required in these VM's"
                      } else { 
                      $NewDesc = "PERM-"+$($Snap.description)
                      get-vm -name $($snap.vm) | get-snapshot -name $($Snap.name) | set-snapshot -description $NewDesc
                      }
                  }
disconnect-viserver -Server $VC -Force -confirm:$False
}
}
rpr
  • 111
  • 2
  • 5
  • 16
  • nobody online just to give a light on it ? – rpr May 19 '18 at 13:38
  • Hey stackoverflow.... Any help ? – rpr May 21 '18 at 03:09
  • Get-VM | Get-Snapshot | Where {$_.Name -notmatch "NBU_SNAPSHOT" -and $_.description -notmatch "PERM" } | set-snapshot -description ("PERM" + $_.description) | select vm, name, description VM Name Description -- ---- ----------- PDRSQ01 test PERM PDRVC01 test PERM PDMI... S... PERM SRMAPP3 S... PERM MPDMD... C.. PERM MPDMD... S.. PERM PRMAPP4 S... PERM VMUDMI... S. PERM DDMA... S... PERM MPDMD... S...PERM PSPWTE... C. PERM MUMYS... V.. PERM I need to get the "PERM + Old description" as output , How to do it ? – rpr May 21 '18 at 03:14
  • `code`Get-VM | Get-Snapshot | Where {$_.Name -notmatch "NBU_SNAPSHOT" -and $_.description -notmatch "PERM" } | set-snapshot -description ("PERM" + $_.description) | select vm, name, description`code` VM Name Description -- ---- ----------- PDRSQ01 test PERM PDRVC01 test PERM PDMI... S... PERM SRMAPP3 S... PERM MPDMD... C.. PERM MPDMD... S.. PERM PRMAPP4 S... PERM VMUDMI... S. PERM DDMA... S... PERM MPDMD... S...PERM PSPWTE... C. PERM MUMYS... V.. PERM I need to get the "PERM + Old description" as output , How to do it ? – rpr May 21 '18 at 04:03

1 Answers1

0
foreach($snap in $AllSnaps){get-vm -name $snap.vm | get-snapshot -name 
$Snap.name | set-snapshot -description "blah"}

Remove the brackets works.

Then the answer might appear as not set as you have to re-get $AllSnaps

user3520245
  • 1,016
  • 1
  • 8
  • 18