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