-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventorylist.ps1
More file actions
122 lines (99 loc) · 4 KB
/
Inventorylist.ps1
File metadata and controls
122 lines (99 loc) · 4 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
#This function creates a list#
#I'm adding another comment#
function setupList ($tempCT)
{
try {
if(!(Get-PnPList -Identity 'ContosoUsedCars'))
{
$list = New-PnPList -Title 'ContosoUsedCars' -Template 'GenericList' -EnableContentTypes
Write-Host 'List Created' -ForegroundColor Green
}
else
{
$list = Get-PnPList -Identity 'ContosoUsedCars'
Write-Host 'List Found!' -ForegroundColor Cyan
}
if(!(Get-PnPContentType -List 'ContosoUsedCars' | ?{$_.Name -eq 'TestCT'}))
{
Add-PnPContentTypeToList -ContentType $tempCT -List $list -DefaultContentType
Write-Host 'ContentType added to list' -ForegroundColor Green
}
else
{Write-Host "ContentType already added to list" -ForegroundColor Cyan}
if(!(Get-PnPView -List 'ContosoUsedCars' | ?{$_.Title -eq 'MyNewView'}))
{
Add-PnPView -Title 'MyNewView' -List $list -Fields 'Make','Model','Miles','Sold'
Write-Host 'Custom view created' -ForegroundColor Green
}
else
{Write-Host "Custom View Found!" -ForegroundColor Cyan}
}
catch [Exception]
{Write-Host "Exception caught attempting to setup list" $_.Exception -ForegroundColor Red}
}
function addColumnstoContentType ($tempCT,$myCols)
{
$cols = $myCols
try {
foreach($col in $cols)
{Add-PnPFieldToContentType -Field $col -ContentType $tempCT}
#Go Setup List
setupList $tempCT
}
catch [Exception]
{Write-Host “Exception caught attempting to add site columns to content type” $_.Exception -ForegroundColor Red}
}
function createContentType ($siteCols)
{
try {
if(!(get-pnpcontenttype -identity "TestCT"))
{
$newCT = add-pnpcontenttype -Name "TestCT" -Description "Contoso Test CT" -Group "Custom" -ParentContentType $itemCT
Write-Host 'Created custom content type' -ForegroundColor Green
addColumnstoContentType $newCT $siteCols
}
else
{
Write-Host "Content Type Found!" -ForegroundColor Cyan
$newCT = get-pnpcontenttype -identity "TestCT"
addColumnstoContentType $newCT $siteCols
}
}
catch [Exception]
{Write-Host “Exception caught attempting to create content type” $_.Exception -ForegroundColor Red}
}
function createSiteColumns()
{
try {
$mySiteColumns = @()
if(!(get-pnpfield | ?{$_.Title -eq 'Make'}))
{$mySiteColumns += add-pnpfield -Type 'text' -DisplayName 'Make' -InternalName 'Make' -Group 'custom'}
else
{$mySiteColumns += get-pnpfield -identity 'Make'}
if(!(get-pnpfield | ?{$_.Title -eq 'Model'}))
{$mySiteColumns += add-pnpfield -Type 'text' -DisplayName 'Model' -InternalName 'Model' -Group 'custom'}
else
{$mySiteColumns += get-pnpfield -Identity 'Model'}
if(!(get-pnpfield | ?{$_.Title -eq 'Miles'}))
{$mySiteColumns += add-pnpfield -Type 'number' -DisplayName 'Miles' -InternalName 'Miles' -Group 'custom'}
else
{$mySiteColumns += get-pnpfield -Identity 'Miles'}
if(!(get-pnpfield | ?{$_.Title -eq 'Sold'}))
{$mySiteColumns += add-pnpfield -Type 'choice' -DisplayName 'Sold' -InternalName 'Sold' -Group 'custom' -choices 'Decision Pending','Yes','No'}
else
{$mySiteColumns += get-pnpfield -Identity 'Sold'}
###Go Create ContentType
createContentType $mySiteColumns
}
catch [Exception]
{Write-Host “Exception caught attempting to create site columns” $_.Exception -ForegroundColor Red}
}
try {
##Module is loaded up so connect to tenant##
Write-Host "Connecting to your tenant"
Write-Host
Connect-PnPOnline -Url 'https://m365x475871.sharepoint.com/sites/test25' -UseWebLogin
createSiteColumns
}
catch [Exception]
{Write-Host "Module is not loaded or you hit an exception: " $_.Exception -ForegroundColor Red }