This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetUrns.ps1
56 lines (48 loc) · 1.79 KB
/
getUrns.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
51
52
53
54
55
56
#############################################################
# This script gets URNs of some model of specific folder using Data Management API of Forge.
# It only extracts first page of the folder. The response data will be output to
# .\out\folder-contents.json file
#############################################################
param
(
# The project containing the files to be indexed
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $ProjectId,
# The folder containing the files to be indexed
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $FolderUrn,
# Forge auth token.
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $ForgeToken
)
#############################################################
# Forge CLI module import
#############################################################
$modulePath = Join-Path $PSScriptRoot '..\src\ForgeCLI.psd1' -Resolve;
Import-Module $modulePath;
#############################################################
# Output variables
#############################################################
$outDir = "$PSScriptRoot\out";
#############################################################
# Main
#############################################################
try {
# create the token
Set-ForgeToken -Token $ForgeToken;
#Data Management API requires project id with 'b.'
$response = Get-ForgeFolderContents -ProjectId $ProjectId -FolderUrn $FolderUrn;
# create the output dir if it does not exist
if (-not(Test-Path $outDir))
{
New-Item -Path $outDir -ItemType Directory | Out-Null;
}
if ($null -ne $response) {
$response | ConvertTo-Json -depth 10 | Out-File "$outDir\folder-contents.json";
} else {
$_;
}
}
catch {
$_;
}