-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGetOrchestratorActivePackages.ps1
More file actions
86 lines (65 loc) · 3.64 KB
/
GetOrchestratorActivePackages.ps1
File metadata and controls
86 lines (65 loc) · 3.64 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
############# EDIT the following section #############
$TenantConfig = [PSCustomObject]@{
'url' = "****** TODO *******"
'tenant' = "****** TODO *******"
'username' = "****** TODO *******"
'password' = "****** TODO *******"
'tokenExpirationInMinutes' = 30
}
$LocalPackageFolder = "****** TODO *******" #local folder where packages will be downloaded, unpacked and analyzed
# You can Disable Debug logs by commenting the next line
$DebugPreference = 'Continue'
######################################################
Import-Module UiPath.PowerShell
########################################
function GetFilesFromNupkg
{
Param([PSObject] $nupkgFilePath, [PSObject] $destinationFolder)
$nupkgFile = Get-Item -Path $nupkgFilePath
$zipFilePath = $nupkgFile.DirectoryName + "\" + $nupkgFile.BaseName + ".zip"
Rename-Item $nupkgFilePath $zipFilePath
Expand-Archive $zipFilePath $destinationFolder
Get-ChildItem -path $destinationFolder -Exclude 'lib' | Remove-Item -Recurse -force
Rename-Item "$destinationFolder\lib" "$destinationFolder\lib-temp-move"
dir "$destinationFolder\lib-temp-move\net45" | mv -dest $destinationFolder
Remove-Item "$destinationFolder\lib-temp-move\" -Recurse -force
Rename-Item $zipFilePath $nupkgFilePath
}
function GetActivePackages
{
Param([PSObject] $tenantConfig, [PSObject] $packageFolder)
$downloadedPackageFolders = New-Object System.Collections.ArrayList
$authResponse = Get-UiPathAuthToken -URL $tenantConfig.url -TenantName $tenantConfig.tenant -Username $tenantConfig.username -Password $tenantConfig.password -Session
$packages = Get-UiPathPackage | Get-UiPathPackageVersion
$activePackages = $packages | Where-Object {$_.IsActive}
Write-Debug "Found packages: $($packages.Count) Active packages: $($activePackages.Count)"
# For a large number of files to be uploaded, re-authentication is required periodically
$authTime = Get-Date -Year 1970 #seeting this to ensure authentication at first iteration
foreach($package in $activePackages)
{
# If we have less than 5 minutes before token expiration, perform an authentication
if (((Get-Date) - $authTime).TotalMinutes -gt ($tenantConfig.tokenExpirationInMinutes - 5))
{
$authTime = Get-Date
$authResponse = Get-UiPathAuthToken -URL $tenantConfig.url -TenantName $tenantConfig.tenant -Username $tenantConfig.username -Password $tenantConfig.password -Session
}
try
{
$endpoint = "$($tenantConfig.url)/odata/Processes/UiPath.Server.Configuration.OData.DownloadPackage(key='$($package.Key)')"
$fileName = "$packageFolder\$($package.Id)_$($package.Version).nupkg"
$extractionFolder = "$packageFolder\$($package.Id)_$($package.Version)"
Write-Debug "Downloading $fileName and extracting to $extractionFolder"
$response = Invoke-WebRequest -Uri $endpoint -Method GET -Headers @{"Authorization"="Bearer " + $authResponse.Token; "accept"= "image/file"} -OutFile $fileName
GetFilesFromNupkg $fileName $extractionFolder
$downloadedPackageFolders.Add($extractionFolder)
}
catch
{
Write-Error "ERROR downloading package <$packageName>: $_ at line $($_.InvocationInfo.ScriptLineNumber)"
}
}
}
####################### Execution Steps #######################
$downloadedPackages = GetActivePackages $TenantConfig $LocalPackageFolder
$projectFiles = (Get-ChildItem -Path $LocalPackageFolder -Force -Recurse -Filter "project.json")
###############################################################