-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetListSchema.ps1
More file actions
148 lines (130 loc) · 5.73 KB
/
GetListSchema.ps1
File metadata and controls
148 lines (130 loc) · 5.73 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Clear
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
#Getting the current path of CSOM dll
$currentpath = (Get-Item -Path ".\" -Verbose).FullName+'\'
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Write-Host "Load CSOM libraries" -foregroundcolor black -backgroundcolor yellow
Set-Location $PSScriptRoot
$dll1 = "$currentpath" + "Microsoft.SharePoint.Client.dll"
$dll2 = "$currentpath" + "Microsoft.SharePoint.Client.Runtime.dll"
$dll3 = "$currentpath" + "Microsoft.SharePoint.Client.Taxonomy.dll"
Add-Type -Path $dll1
Add-Type -Path $dll2
Add-Type -Path $dll3
Write-Host "CSOM libraries loaded successfully" -foregroundcolor black -backgroundcolor Green
#Credentials to connect to office 365 site collection url
$url =Read-Host -Prompt "Please enter site collection url"
$username =Read-Host -Prompt "Please enter User Name"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
## The following four lines only need to be declared once in your script.
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Description."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Description."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
## Use the following each time your want to prompt the use
$title = "Title"
$message = "Is it for SharePoint Online?"
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result) {
0{
$result= "Yes"
}
1{
$result= "No"
}
}
#Loading the Site context
Write-Host "Authenticate to SharePoint Online site collection $url and get ClientContext object" -foregroundcolor black -backgroundcolor yellow
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
if($result -eq "Yes"){
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$Context.Credentials = $credentials
}
else{
$credentials = New-Object System.Net.NetworkCredential($username, $password)
$Context.Credentials = $credentials
}
$arraySiteColumns = @()
$array =@()
$SPOLists=""
$listCT=""
$allContentTypes=""
$xmlFilePath = "C:\Install\ListSchema.json"
#Create Export Files
New-Item $xmlFilePath -type file -force
$web=$Context.Web
$SPOLists=$web.Lists
$Context.Load($SPOLists)
$Context.ExecuteQuery()
##OOB SharePoint Lists to exclude from Export
$ListsNameToExclude = "_catalogs,Lists/ContentTypeSyncLog,/IWConvertedForms,FormServerTemplates,Lists/PublishedFeed,/ProjectPolicyItemList,/SiteAssets,/SitePages,/Style Library,Lists/TaxonomyHiddenList"
$ArrayListtoExcl = $ListsNameToExclude.Split(",");
foreach($list in $SPOLists)
{
if($list.Hidden -ne $true )
{
$item = New-Object PSObject
Write-Host "List Name :"$list.Title
$list = $web.Lists.GetByTitle($list.Title)
$Context.Load($list)
$LitsLookupField=$list.Fields
$Context.Load($LitsLookupField)
$Context.ExecuteQuery()
$LitsInternalName=$list.EntityTypeName.replace('_x0020_',' ')
if($list.BaseType -eq "GenericList")
{
$LitsInternalName=$LitsInternalName.Substring(0,$LitsInternalName.Length-4)
}
$item | Add-Member -type NoteProperty -Name 'SListInternalName' -Value $($LitsInternalName)
$item | Add-Member -type NoteProperty -Name 'SListType' -Value $($list.BaseType.ToString())
$item | Add-Member -type NoteProperty -Name 'SListTitle' -Value $($list.Title)
$item | Add-Member -type NoteProperty -Name 'SListDescription' -Value $($list.Description)
$item | Add-Member -type NoteProperty -Name 'SListHidden' -Value $($list.Hidden)
$item | Add-Member -type NoteProperty -Name 'SListLookupField' -Value $($LitsLookupField.SchemaXml)
if($list.ContentTypesEnabled -eq $true)
{
$defaultCT=""
$allContentTypes=""
$listCT=$list.ContentTypes
$Context.Load($listCT)
$Context.ExecuteQuery()
$allContentTypes=""
$defaultCT=$listCT[0].Name
$contentTypeObj = @()
foreach($scontentType in $listCT)
{
$listContentType=$scontentType.Fields
$context.load($listContentType)
$context.ExecuteQuery()
$aryCTFields=@()
$contentTypeObjFields=@()
ForEach ($field in $listContentType)
{
$aryCTFields = @{ 'FieldName' = $field.Title
'FieldRequired' = $field.Required
'FieldHidden' = $field.Hidden
'FieldReadOnly' = $field.ReadOnlyField
'DisplayName' = $field.Title
'InternalName' = $field.InternalName
}
$contentTypeObjFields+=$aryCTFields
$aryCTFields=@()
}
$contentTypeObjFields= $contentTypeObjFields | ConvertTo-Json
#$allContentTypes += $scontentType.Name +";"
$array = @{ 'ContentTypeName' = $scontentType.Name
'ContentTypeFields' = $contentTypeObjFields
}
$contentTypeObj+=$array
$array=@()
}
$item | Add-Member -type NoteProperty -Name 'SListContentTypesEnabled' -Value $($list.ContentTypesEnabled)
$item | Add-Member -type NoteProperty -Name 'SDefaultContentType' -Value $($defaultCT)
$contentTypeObj = $contentTypeObj | ConvertTo-Json
$item | Add-Member -type NoteProperty -Name 'SAllContentTypeNames' -Value $($contentTypeObj)
}
$arraySiteColumns += $item
}
}
$bSitecolumns = @()
$bSitecolumns=$arraySiteColumns | ConvertTo-Json
Add-Content $xmlFilePath $bSitecolumns