Skip to content

Commit ce06c53

Browse files
committed
Added git sync script and fixed an issue in the
remove old snapshots script in the PowerActions folder
1 parent 20871ae commit ce06c53

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

PowerActions/Example - RemoveOldClusterSnapshots.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $vms = Get-VM -Location $cluster
1111
foreach ($vm in $vms) {
1212
$snaphostsToBeRemoved = Get-Snapshot -VM $vm | where {$_.Created -lt $date}
1313
if ($null -ne $snaphostsToBeRemoved) {
14-
Write-Host "Removing snapshots: " + $snaphostsToBeRemoved + " of VM: " + $vm
14+
Write-Host "Removing snapshots: '$snaphostsToBeRemoved' of VM: '$vm'"
1515
Remove-Snapshot $snaphostsToBeRemoved -Confirm:$false
1616
}
1717
}

PowerActions/Git Sync.ps1

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#Intall git
2+
tdnf install -y git
3+
4+
#Clone the repo
5+
git clone -n --depth=1 --filter=tree:0 https://github.com/vmware/PowerCLI-Example-Scripts.git
6+
cd PowerCLI-Example-Scripts
7+
git sparse-checkout set --no-cone PowerActions
8+
git checkout
9+
cd PowerActions
10+
11+
#Select the content library in which you want to store the scirpts from the repo
12+
$contentLibraryName = 'Power Actions'
13+
$contentLibrary = Get-ContentLibrary $contentLibraryName
14+
15+
#Get all the files that we have cloned from the repo
16+
$files = Get-ChildItem -Path . -File
17+
foreach ($file in $files) {
18+
$name = $file.BaseName
19+
20+
#Check if the item for this file already exists in the content library
21+
$item = Get-ContentLibraryItem -Name $name -ContentLibrary $contentLibrary -ErrorAction SilentlyContinue
22+
if ($item) {
23+
#If the item exists, check if it is up to date
24+
#Create a folder to store the current content library item
25+
if (-not (Test-Path -Path ./cl_versions -PathType Container))
26+
{
27+
New-Item -Path ./cl_versions -ItemType Directory
28+
}
29+
#Download the item from the content library
30+
$clFile = Export-ContentLibraryItem -ContentLibraryItem $item -Destination ((Get-Location).Path + "/cl_version") -Force
31+
#Compare if it's the same as the file we have downloaded from the repo
32+
$compResult = Compare-Object -ReferenceObject (Get-Content $file.FullName) -DifferenceObject (Get-Content ($clFile.FullName+"/"+$file.Name))
33+
if ($compResult) {
34+
#If the item is not up to date, update it
35+
Write-Host "Updating $name"
36+
Set-ContentLibraryItem -ContentLibraryItem $item -Files $file.FullName
37+
} else {
38+
Write-Host "$name is up to date"
39+
}
40+
} else {
41+
#If the item does not exist, create it
42+
New-ContentLibraryItem -Name $name -Files $file.FullName -ContentLibrary $contentLibrary
43+
}
44+
}

0 commit comments

Comments
 (0)