-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathExport-RVTools.ps1
50 lines (43 loc) · 1.35 KB
/
Export-RVTools.ps1
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
39
40
41
42
43
44
45
46
47
48
49
50
<#
.SYNOPSIS
Performs full export from RVTools
.DESCRIPTION
Performs full export from RVTools. Archives old versions.
.NOTES
File Name : RVToolsExport.ps1
Author : John Sneddon
Version : 1.0.1
.PARAMETER Servers
Specify which vCenter server(s) to connect to
.PARAMETER BasePath
Specify the path to export to. Server name and date appended.
.PARAMETER OldFileDays
How many days to retain copies
#>
param
(
$Servers = @("VCENTER"),
$BasePath = "C:\Scripts\Powershell\RVToolsExport\Archive",
$OldFileDays = 30
)
$Date = (Get-Date -f "yyyyMMdd")
foreach ($Server in $Servers)
{
# Create Directory
New-Item -Path "$BasePath\$Server\$Date" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
# Run Export
. "C:\Program Files (x86)\RobWare\RVTools\RVTools.exe" -passthroughAuth -s $Server -c ExportAll2csv -d "$BasePath\$Server\$Date"
# Cleanup old files
$Items = Get-ChildItem -Directory "$BasePath\$server"
foreach ($item in $items)
{
$itemDate = ("{0}/{1}/{2}" -f $item.name.Substring(6,2),$item.name.Substring(4,2),$item.name.Substring(0,4))
if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days -gt 0)
{
$item | Remove-Item -Recurse
}
}
}
# Changelog:
# 1.0.0 - Initial release
# 1.0.1 - Fixed cleanup routine with uninitialised variable $path