Skip to content

Commit 9903fe2

Browse files
committed
fixup
1 parent 82ccd18 commit 9903fe2

File tree

2 files changed

+94
-94
lines changed

2 files changed

+94
-94
lines changed

scripts/spo-add-fields-to-contenttypes/README.md

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -122,114 +122,114 @@ begin {
122122
}
123123
124124
$Script:Results = [System.Collections.Generic.List[pscustomobject]]::new()
125-
}
126125
127-
function Ensure-SiteField {
128-
param (
129-
[Parameter(Mandatory = $true)] [string]$WebUrl,
130-
[Parameter(Mandatory = $true)] [System.Collections.Hashtable]$Definition
131-
)
126+
function Ensure-SiteField {
127+
param (
128+
[Parameter(Mandatory = $true)] [string]$WebUrl,
129+
[Parameter(Mandatory = $true)] [System.Collections.Hashtable]$Definition
130+
)
132131
133-
$fieldLookup = m365 spo field list --webUrl $WebUrl --output json | ConvertFrom-Json
134-
$existingField = $fieldLookup | Where-Object { $_.Title -eq $Definition.FieldName -or $_.InternalName -eq $Definition.FieldName -or $_.Id -eq $Definition.FieldId }
132+
$fieldLookup = m365 spo field list --webUrl $WebUrl --output json | ConvertFrom-Json
133+
$existingField = $fieldLookup | Where-Object { $_.Title -eq $Definition.FieldName -or $_.InternalName -eq $Definition.FieldName -or $_.Id -eq $Definition.FieldId }
134+
135+
if ($existingField) {
136+
$Script:Results.Add([pscustomobject]@{
137+
Action = 'Field'
138+
Target = $Definition.FieldName
139+
Status = 'Skipped'
140+
Message = 'Field already exists'
141+
})
142+
return $existingField
143+
}
135144
136-
if ($existingField) {
137-
$Script:Results.Add([pscustomobject]@{
138-
Action = 'Field'
139-
Target = $Definition.FieldName
140-
Status = 'Skipped'
141-
Message = 'Field already exists'
142-
})
143-
return $existingField
144-
}
145+
if (-not $PSCmdlet.ShouldProcess($Definition.FieldName, 'Create site column')) {
146+
$Script:Results.Add([pscustomobject]@{
147+
Action = 'Field'
148+
Target = $Definition.FieldName
149+
Status = 'WhatIf'
150+
Message = 'Field creation skipped'
151+
})
152+
return $null
153+
}
145154
146-
if (-not $PSCmdlet.ShouldProcess($Definition.FieldName, 'Create site column')) {
147-
$Script:Results.Add([pscustomobject]@{
148-
Action = 'Field'
149-
Target = $Definition.FieldName
150-
Status = 'WhatIf'
151-
Message = 'Field creation skipped'
152-
})
153-
return $null
154-
}
155+
$createOutput = m365 spo field add --webUrl $WebUrl --xml $Definition.FieldXml --output json 2>&1
156+
if ($LASTEXITCODE -ne 0) {
157+
$Script:Results.Add([pscustomobject]@{
158+
Action = 'Field'
159+
Target = $Definition.FieldName
160+
Status = 'Failed'
161+
Message = $createOutput
162+
})
163+
return $null
164+
}
155165
156-
$createOutput = m365 spo field add --webUrl $WebUrl --xml $Definition.FieldXml --output json 2>&1
157-
if ($LASTEXITCODE -ne 0) {
166+
$createdField = $createOutput | ConvertFrom-Json
158167
$Script:Results.Add([pscustomobject]@{
159-
Action = 'Field'
160-
Target = $Definition.FieldName
161-
Status = 'Failed'
162-
Message = $createOutput
163-
})
164-
return $null
168+
Action = 'Field'
169+
Target = $Definition.FieldName
170+
Status = 'Created'
171+
Message = 'Field created successfully'
172+
})
173+
return $createdField
165174
}
166175
167-
$createdField = $createOutput | ConvertFrom-Json
168-
$Script:Results.Add([pscustomobject]@{
169-
Action = 'Field'
170-
Target = $Definition.FieldName
171-
Status = 'Created'
172-
Message = 'Field created successfully'
173-
})
174-
return $createdField
175-
}
176+
function Add-FieldToContentType {
177+
param (
178+
[Parameter(Mandatory = $true)] [string]$WebUrl,
179+
[Parameter(Mandatory = $true)] [string]$ContentTypeName,
180+
[Parameter(Mandatory = $true)] [System.Collections.Hashtable]$Definition
181+
)
176182
177-
function Add-FieldToContentType {
178-
param (
179-
[Parameter(Mandatory = $true)] [string]$WebUrl,
180-
[Parameter(Mandatory = $true)] [string]$ContentTypeName,
181-
[Parameter(Mandatory = $true)] [System.Collections.Hashtable]$Definition
182-
)
183+
$contentTypeJson = m365 spo contenttype get --webUrl $WebUrl --name $ContentTypeName --output json 2>&1
184+
if ($LASTEXITCODE -ne 0) {
185+
$Script:Results.Add([pscustomobject]@{
186+
Action = 'ContentType'
187+
Target = $ContentTypeName
188+
Status = 'Failed'
189+
Message = $contentTypeJson
190+
})
191+
return
192+
}
183193
184-
$contentTypeJson = m365 spo contenttype get --webUrl $WebUrl --name $ContentTypeName --output json 2>&1
185-
if ($LASTEXITCODE -ne 0) {
186-
$Script:Results.Add([pscustomobject]@{
187-
Action = 'ContentType'
188-
Target = $ContentTypeName
189-
Status = 'Failed'
190-
Message = $contentTypeJson
191-
})
192-
return
193-
}
194+
$contentType = $contentTypeJson | ConvertFrom-Json
195+
if (-not $contentType.StringId) {
196+
$Script:Results.Add([pscustomobject]@{
197+
Action = 'ContentType'
198+
Target = $ContentTypeName
199+
Status = 'Failed'
200+
Message = 'Content type not found'
201+
})
202+
return
203+
}
194204
195-
$contentType = $contentTypeJson | ConvertFrom-Json
196-
if (-not $contentType.StringId) {
197-
$Script:Results.Add([pscustomobject]@{
198-
Action = 'ContentType'
199-
Target = $ContentTypeName
200-
Status = 'Failed'
201-
Message = 'Content type not found'
202-
})
203-
return
204-
}
205+
if (-not $PSCmdlet.ShouldProcess($ContentTypeName, "Add field $($Definition.FieldName)")) {
206+
$Script:Results.Add([pscustomobject]@{
207+
Action = 'ContentType'
208+
Target = $ContentTypeName
209+
Status = 'WhatIf'
210+
Message = "Skipped adding field $($Definition.FieldName)"
211+
})
212+
return
213+
}
205214
206-
if (-not $PSCmdlet.ShouldProcess($ContentTypeName, "Add field $($Definition.FieldName)")) {
207-
$Script:Results.Add([pscustomobject]@{
208-
Action = 'ContentType'
209-
Target = $ContentTypeName
210-
Status = 'WhatIf'
211-
Message = "Skipped adding field $($Definition.FieldName)"
212-
})
213-
return
214-
}
215+
$setOutput = m365 spo contenttype field set --webUrl $WebUrl --contentTypeId $contentType.StringId --id $Definition.FieldId --output json 2>&1
216+
if ($LASTEXITCODE -ne 0) {
217+
$Script:Results.Add([pscustomobject]@{
218+
Action = 'ContentType'
219+
Target = $ContentTypeName
220+
Status = 'Failed'
221+
Message = $setOutput
222+
})
223+
return
224+
}
215225
216-
$setOutput = m365 spo contenttype field set --webUrl $WebUrl --contentTypeId $contentType.StringId --id $Definition.FieldId --output json 2>&1
217-
if ($LASTEXITCODE -ne 0) {
218226
$Script:Results.Add([pscustomobject]@{
219-
Action = 'ContentType'
220-
Target = $ContentTypeName
221-
Status = 'Failed'
222-
Message = $setOutput
223-
})
224-
return
227+
Action = 'ContentType'
228+
Target = $ContentTypeName
229+
Status = 'Updated'
230+
Message = "Field $($Definition.FieldName) bound successfully"
231+
})
225232
}
226-
227-
$Script:Results.Add([pscustomobject]@{
228-
Action = 'ContentType'
229-
Target = $ContentTypeName
230-
Status = 'Updated'
231-
Message = "Field $($Definition.FieldName) bound successfully"
232-
})
233233
}
234234
235235
process {

scripts/spo-add-fields-to-contenttypes/assets/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
{
6161
"gitHubAccount": "Adam-it",
62-
"pictureUrl": "https://github.com/Adam-it.png",
62+
"pictureUrl": "https://avatars.githubusercontent.com/u/58668583?v=4",
6363
"name": "Adam Wójcik"
6464
}
6565
],

0 commit comments

Comments
 (0)