-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBackupVMwarehostConfig.ps1
More file actions
38 lines (30 loc) · 983 Bytes
/
Copy pathBackupVMwarehostConfig.ps1
File metadata and controls
38 lines (30 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Import VMware CLI modul
Import-module -Name VMware.PowerCLI
#Login for vCenter
$User = ""
$Password = ""
$vCenterIP = ""
#Backup Location
$BackupLocation = ""
#Creates a folder to put the backup files with name of todays date.
New-Item -ItemType Directory -Path $BackupLocation\$((Get-Date).ToShortDateString())
#Connect to vCenter
Connect-viserver $vCenterIP -User $User -Password $Password
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$false
#Get VMware hots
$VMhosts = Get-VMHost
foreach ($VMhost in $VMhosts) {
Get-VMHostFirmware -VMHost $VMhost -BackupConfiguration -DestinationPath "$BackupLocation\$((Get-Date).ToShortDateString())"
}
#Disconnect from vCenter
Disconnect-viserver -Confirm:$false
#Clean Up backup files
$Backups = Get-ChildItem $BackupLocation
$Date = (Get-Date).AddDays(-14).ToShortDateString()
Foreach ($Backup in $Backups)
{
if ($Backup.Name -lt $Date)
{
Remove-Item $Backup.Name -Force -Verbose
}
}