So I am new to Powershell Scripting. I know enough to get me by. But I know the below script can be imporoved upon. I know its a big ask. but can you help me?
Thanks so much in advance.
<code>Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted #Set the execution policy to Unrestricted for current user.
$days = '60' #Set This to how many days to keep snapshots
$days = (Get-Date).AddDays(-$days) #Dont touch this
$Name = Get-Date -Format "dddd dd/MM/yyyy" #Set the current date
$vm1 = 'First_VM_Name' #These variables list the VMs
$vm2 = 'Second_VM_Name'
Echo = 'Removing Old Snapshots on ' $vm1
Get-VMSnapshot -VMName $vm1 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Echo = 'Removing Old Snapshots on ' $vm2
Get-VMSnapshot -VMName $vm2 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Checkpoint-VM -Name $vm1 -SnapshotName $Name #Here we set a new checkpoint / Snapshot
$LocalFolderPathGIT = "C:Plex_MediaDownloadsReplicationGit" #Variables for the Local directory where the snapshots are stored
$RemoteFolderPathGIT = "Z:BackupsGit" #Variables for the Remote directory where the snapshots are stored
Stop-VM $vm1 #Stopping the VM
RoboCopy $LocalFolderPathGIT $RemoteFolderPathGIT /MIR /FFT /Z /XA:H /W:5 #Syncing between local and remote
Start-VM $vm1
Checkpoint-VM -Name $vm2 -SnapshotName $Name
$LocalFolderPathwww = "C:Plex_MediaDownloadsReplicationwww"
$RemoteFolderPathwww = "Z:Backupswww"
Stop-VM $vm2
RoboCopy $LocalFolderPathwww $RemoteFolderPathwww /MIR /FFT /Z /XA:H /W:5
Start-VM $vm2
</code>
<code>Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted #Set the execution policy to Unrestricted for current user.
$days = '60' #Set This to how many days to keep snapshots
$days = (Get-Date).AddDays(-$days) #Dont touch this
$Name = Get-Date -Format "dddd dd/MM/yyyy" #Set the current date
$vm1 = 'First_VM_Name' #These variables list the VMs
$vm2 = 'Second_VM_Name'
Echo = 'Removing Old Snapshots on ' $vm1
Get-VMSnapshot -VMName $vm1 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Echo = 'Removing Old Snapshots on ' $vm2
Get-VMSnapshot -VMName $vm2 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Checkpoint-VM -Name $vm1 -SnapshotName $Name #Here we set a new checkpoint / Snapshot
$LocalFolderPathGIT = "C:Plex_MediaDownloadsReplicationGit" #Variables for the Local directory where the snapshots are stored
$RemoteFolderPathGIT = "Z:BackupsGit" #Variables for the Remote directory where the snapshots are stored
Stop-VM $vm1 #Stopping the VM
RoboCopy $LocalFolderPathGIT $RemoteFolderPathGIT /MIR /FFT /Z /XA:H /W:5 #Syncing between local and remote
Start-VM $vm1
Checkpoint-VM -Name $vm2 -SnapshotName $Name
$LocalFolderPathwww = "C:Plex_MediaDownloadsReplicationwww"
$RemoteFolderPathwww = "Z:Backupswww"
Stop-VM $vm2
RoboCopy $LocalFolderPathwww $RemoteFolderPathwww /MIR /FFT /Z /XA:H /W:5
Start-VM $vm2
</code>
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted #Set the execution policy to Unrestricted for current user.
$days = '60' #Set This to how many days to keep snapshots
$days = (Get-Date).AddDays(-$days) #Dont touch this
$Name = Get-Date -Format "dddd dd/MM/yyyy" #Set the current date
$vm1 = 'First_VM_Name' #These variables list the VMs
$vm2 = 'Second_VM_Name'
Echo = 'Removing Old Snapshots on ' $vm1
Get-VMSnapshot -VMName $vm1 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Echo = 'Removing Old Snapshots on ' $vm2
Get-VMSnapshot -VMName $vm2 | Where-Object {$_.CreationTime -lt $days } | Remove-VMSnapshot #Remove the snapshots older than the above set days
Checkpoint-VM -Name $vm1 -SnapshotName $Name #Here we set a new checkpoint / Snapshot
$LocalFolderPathGIT = "C:Plex_MediaDownloadsReplicationGit" #Variables for the Local directory where the snapshots are stored
$RemoteFolderPathGIT = "Z:BackupsGit" #Variables for the Remote directory where the snapshots are stored
Stop-VM $vm1 #Stopping the VM
RoboCopy $LocalFolderPathGIT $RemoteFolderPathGIT /MIR /FFT /Z /XA:H /W:5 #Syncing between local and remote
Start-VM $vm1
Checkpoint-VM -Name $vm2 -SnapshotName $Name
$LocalFolderPathwww = "C:Plex_MediaDownloadsReplicationwww"
$RemoteFolderPathwww = "Z:Backupswww"
Stop-VM $vm2
RoboCopy $LocalFolderPathwww $RemoteFolderPathwww /MIR /FFT /Z /XA:H /W:5
Start-VM $vm2
2