-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-HUSPArchivedMetadata.ps1
55 lines (47 loc) · 1.87 KB
/
Get-HUSPArchivedMetadata.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
<#
################################################################
.Synopsis
Gets the Archived Metadata from documents imported from WISDOM
.DESCRIPTION
Gets the XML Archived Metadata from WISDOM which is stored with each document and saves it to the audit log folder in each web for a specified document
.Parameter url
A valid SharePoint Web Site Url
.Parameter list
A valid SharePoint List name
.Parameter id
A valid document ID integer
.OUTPUTS
An XML file in the audit reports folder containing the XML data from the Archived Metadata field
.EXAMPLE
Get-HUSPArchivedMetadata -url https://testunifunctions.hud.ac.uk/COM/University-Committees -list "University Health and Safety Committee" -id 173
################################################################
#>
function Get-HUSPArchivedMetadata {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$url,
[Parameter(Mandatory=$True,Position=2)]
[string]$list,
[Parameter(Mandatory=$True,Position=2)]
[string]$id
)
$SPWeb = Get-SPWeb $url
$SPList = $SPWeb.Lists[$list]
$SPItem = $SPList.GetItemById($id)
$SPArchivedMetadata = $SPItem["Archived Metadata"].ToString()
# Save the XML string to a file in Audit Reports
$SPXmlFileName = ".\SPLogs\" +$SPItem["Document ID Value"] + ".xml"
$SPSiteUrl = $SPWeb.Url
$SPSiteAuditFolder = "@Audit Reports"
Add-Content $SPXmlFileName $SPArchivedMetadata
$SPXmlFile = Get-Item $SPXmlFileName
$SPStream = $SPXmlFile.OpenRead()
$SPUploadList = $SPWeb.Lists[$SPSiteAuditFolder]
$SPFileCollection = $SPUploadList.RootFolder.Files
Write-Verbose $SPXmlFile.Name
$SPFileCollection.Add($SPXmlFile.Name,$SPStream,$true)
$SPStream.Close()
$SPXmlFile.Delete()
$SPWeb.Dispose()
}