-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportSharePointMetaData.ps1
83 lines (71 loc) · 2.75 KB
/
ExportSharePointMetaData.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
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
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$SiteUrl,
[Parameter(Mandatory = $true)]
[string]
$DocumentLibrary
)
BEGIN {
$ErrorActionPreference = "Stop"
# Disconnect PNP Online
try {
Disconnect-PnPOnline
}
Catch {}
# Connect PNP Online
Connect-PnPOnline -Url $SiteUrl -UseWebLogin
# Get all Taxonomy IDs
Write-Host "Getting all Taxonomies..." -NoNewline
$sourceTermIds = Export-PnPTaxonomy -IncludeID
Write-Host "DONE" -ForegroundColor Green
function LookupTerm($TermGuid) {
$Result = $sourceTermIds | Where-Object { ($_ -split ";")[-1] -eq "#$TermGuid" }
$Result = ($Result -split ";" | ForEach-Object { $_ -split "\|" | Where-Object { $_ -notlike "#*" } }) -join "|"
return $Result
}
function GetFieldValue($Value, $FileListItem) {
$Field_Value = $FileListItem.FieldValues[$Value]
$Field_Label = $Field_Value.Label
$Field_Guid = $Field_Value.TermGuid
$Field_FullPath = LookupTerm -TermGuid $Field_Guid
$Results = [PSCustomObject]@{
Value = $Field_Value
Label = $Field_Label
Guid = $Field_Guid
FullPath = $Field_FullPath
}
return $Results
}
}
PROCESS {
Write-Host "Getting files in $DocumentLibrary..." -NoNewline
$Files = Get-PnPFolderItem -FolderSiteRelativeUrl $DocumentLibrary -ItemType File
Write-Host "DONE" -ForegroundColor Green
$Total = $Files | Measure-Object | Select-Object -ExpandProperty Count
$i = 0
foreach ($File in $files) {
Write-Progress -Activity "Getting file metadata..." -Status "Files: [ $i / $Total ]" -PercentComplete (($i / $Total) * 100)
$i++
$Name = $File.Name
$RelativePath = $File.ServerRelativeUrl
$PNPFileListItem = Get-PnPFile -AsListItem -Url $RelativePath
$Vendor = GetFieldValue -Value "Vendor" -FileListItem $PNPFileListItem
$Vehicle = GetFieldValue -Value "Vehicle" -FileListItem $PNPFileListItem
$Customers = GetFieldValue -Value "Customers" -FileListItem $PNPFileListItem
$Manufacturer = GetFieldValue -Value "Product" -FileListItem $PNPFileListItem
[PSCustomObject]@{
FileName = $Name
RelativePath = $RelativePath
VendorLabel = $Vendor.Label
VendorFullPath = $Vendor.FullPath
VehicleLabel = $Vehicle.Label
VehicleFullPath = $Vehicle.FullPath
CustomersLabel = $Customers.Label
CustomersFullPath = $Customers.FullPath
ManufacturerLabel = $Manufacturer.Label
ManufacturerFullPath = $Manufacturer.FullPath
}
}
}