├── SPOMod-Older.rar
├── README.md
└── SPOMod.psm1
/SPOMod-Older.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PowershellScripts/SPOMod/HEAD/SPOMod-Older.rar
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SPOMod
2 | SharePoint Module for managing lists, items and files. The module is a massive work comprising over 3000 lines of code and 50 SharePoint Online cmdlets for managing: lists list columns, list items, files, content types, taxonomy
3 |
--------------------------------------------------------------------------------
/SPOMod.psm1:
--------------------------------------------------------------------------------
1 | #
2 | # Created by Arleta Wanat, 2015
3 | #
4 | # The following cmdlets are a result of passion and hours of work and research.
5 | # They are distributed freely and happily to anyone who needs them in a day-to-day administration
6 | # in hope they will make your work easier and allow you to manage your SharePoint Online
7 | # in ways not possible either through User Interface or Sharepoint Online Management Shell.
8 | #
9 | #
10 | #
11 | # The cmdlets can be used as basis for creating scripts and other solutions.
12 | # If you are using the following code for any of your own works, please acknowledge my contribution.
13 | #
14 | #
15 |
16 |
17 | #region SPOList cmdlets
18 |
19 | function Get-SPOListCount
20 | {
21 | <#
22 | .link
23 | http://social.technet.microsoft.com/wiki/contents/articles/32342.sharepoint-online-spomod-get-spolistcount.aspx
24 | #>
25 |
26 | $ctx.Load($ctx.Web.Lists)
27 | $ctx.ExecuteQuery()
28 | return $ctx.Web.Lists.Count
29 | }
30 |
31 |
32 |
33 |
34 | function Get-SPOList
35 | {
36 | param (
37 | [Parameter(Mandatory=$false,Position=0)]
38 | [switch]$IncludeAllProperties
39 | )
40 | <#
41 | .link
42 | http://social.technet.microsoft.com/wiki/contents/articles/32335.sharepoint-online-spomod-get-spolist.aspx
43 | #>
44 |
45 |
46 | $ctx.Load($ctx.Web.Lists)
47 | $ctx.ExecuteQuery()
48 | Write-Host
49 | Write-Host $ctx.Url -BackgroundColor White -ForegroundColor DarkGreen
50 |
51 | foreach( $ll in $ctx.Web.Lists)
52 | {
53 | $ctx.Load($ll.RootFolder)
54 | $ctx.Load($ll.DefaultView)
55 | $ctx.Load($ll.Views)
56 | $ctx.Load($ll.WorkflowAssociations)
57 | try
58 | {
59 | $ctx.ExecuteQuery()
60 | }
61 | catch
62 | {
63 | #do something
64 | }
65 |
66 | if($IncludeAllProperties)
67 | {
68 | $obj = New-Object PSObject
69 | $obj | Add-Member NoteProperty Title($ll.Title)
70 | $obj | Add-Member NoteProperty Created($ll.Created)
71 | $obj | Add-Member NoteProperty Tag($ll.Tag)
72 | $obj | Add-Member NoteProperty RootFolder.ServerRelativeUrl($ll.RootFolder.ServerRelativeUrl)
73 | $obj | Add-Member NoteProperty BaseType($ll.BaseType)
74 | $obj | Add-Member NoteProperty BaseTemplate($ll.BaseTemplate)
75 | $obj | Add-Member NoteProperty AllowContenttypes($ll.AllowContenttypes)
76 | $obj | Add-Member NoteProperty ContentTypesEnabled($ll.ContentTypesEnabled)
77 | $obj | Add-Member NoteProperty DefaultView.Title($ll.DefaultView.Title)
78 | $obj | Add-Member NoteProperty Description($ll.Description)
79 | $obj | Add-Member NoteProperty DocumentTemplateUrl($ll.DocumentTemplateUrl)
80 | $obj | Add-Member NoteProperty DraftVersionVisibility($ll.DraftVersionVisibility)
81 | $obj | Add-Member NoteProperty EnableAttachments($ll.EnableAttachments)
82 | $obj | Add-Member NoteProperty EnableMinorVersions($ll.EnableMinorVersions)
83 | $obj | Add-Member NoteProperty EnableFolderCreation($ll.EnableFolderCreation)
84 | $obj | Add-Member NoteProperty EnableVersioning($ll.EnableVersioning)
85 | $obj | Add-Member NoteProperty EnableModeration($ll.EnableModeration)
86 | $obj | Add-Member NoteProperty Fields.Count($ll.Fields.Count)
87 | $obj | Add-Member NoteProperty ForceCheckout($ll.ForceCheckout)
88 | $obj | Add-Member NoteProperty Hidden($ll.Hidden)
89 | $obj | Add-Member NoteProperty Id($ll.Id)
90 | $obj | Add-Member NoteProperty IRMEnabled($ll.IRMEnabled)
91 | $obj | Add-Member NoteProperty IsApplicationList($ll.IsApplicationList)
92 | $obj | Add-Member NoteProperty IsCatalog($ll.IsCatalog)
93 | $obj | Add-Member NoteProperty IsPrivate($ll.IsPrivate)
94 | $obj | Add-Member NoteProperty IsSiteAssetsLibrary($ll.IsSiteAssetsLibrary)
95 | $obj | Add-Member NoteProperty ItemCount($ll.ItemCount)
96 | $obj | Add-Member NoteProperty LastItemDeletedDate($ll.LastItemDeletedDate)
97 | $obj | Add-Member NoteProperty MultipleDataList($ll.MultipleDataList)
98 | $obj | Add-Member NoteProperty NoCrawl($ll.NoCrawl)
99 | $obj | Add-Member NoteProperty OnQuickLaunch($ll.OnQuickLaunch)
100 | $obj | Add-Member NoteProperty ParentWebUrl($ll.ParentWebUrl)
101 | $obj | Add-Member NoteProperty TemplateFeatureId($ll.TemplateFeatureId)
102 | $obj | Add-Member NoteProperty Views.Count($ll.Views.Count)
103 | $obj | Add-Member NoteProperty WorkflowAssociations.Count($ll.WorkflowAssociations.Count)
104 | Write-Output $obj
105 | }
106 | else
107 | {
108 | $obj = New-Object PSObject
109 | $obj | Add-Member NoteProperty Title($ll.Title)
110 | $obj | Add-Member NoteProperty Created($ll.Created)
111 | $obj | Add-Member NoteProperty RootFolder.ServerRelativeUrl($ll.RootFolder.ServerRelativeUrl)
112 | Write-Output $obj
113 | }
114 | }
115 | }
116 |
117 |
118 |
119 |
120 | function Set-SPOList
121 | {
122 |
123 | <#
124 | .link
125 | http://social.technet.microsoft.com/wiki/contents/articles/32335.sharepoint-online-spomod-set-spolist.aspx
126 |
127 | #>
128 |
129 | param (
130 | [Parameter(Mandatory=$true,Position=0)]
131 | [string]$ListName,
132 | [Parameter(Mandatory=$false,Position=1)]
133 | [bool]$NoCrawl,
134 | [Parameter(Mandatory=$false,Position=2)]
135 | [string]$Title,
136 | [Parameter(Mandatory=$false,Position=3)]
137 | [string]$Tag,
138 | [Parameter(Mandatory=$false,Position=5)]
139 | [bool]$ContentTypesEnabled,
140 | [Parameter(Mandatory=$false,Position=6)]
141 | [string]$Description,
142 | [Parameter(Mandatory=$false,Position=7)]
143 | [ValidateSet(0,1,2)]
144 | [Int]$DraftVersionVisibility,
145 | [Parameter(Mandatory=$false,Position=8)]
146 | [bool]$EnableAttachments,
147 | [Parameter(Mandatory=$false,Position=8)]
148 | [bool]$EnableMinorVersions,
149 | [Parameter(Mandatory=$false,Position=8)]
150 | [bool]$EnableFolderCreation,
151 | [Parameter(Mandatory=$false,Position=8)]
152 | [bool]$EnableVersioning,
153 | [Parameter(Mandatory=$false,Position=8)]
154 | [bool]$EnableModeration,
155 | [Parameter(Mandatory=$false,Position=8)]
156 | [bool]$ForceCheckout,
157 | [Parameter(Mandatory=$false,Position=8)]
158 | [bool]$Hidden,
159 | [Parameter(Mandatory=$false,Position=8)]
160 | [bool]$IRMEnabled,
161 | [Parameter(Mandatory=$false,Position=8)]
162 | [bool]$IsApplicationList,
163 | [Parameter(Mandatory=$false,Position=8)]
164 | [bool]$OnQuickLaunch
165 | )
166 |
167 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
168 | if($PSBoundParameters.ContainsKey("NoCrawl")) {$ll.NoCrawl=$NoCrawl}
169 | if($PSBoundParameters.ContainsKey("Title")) {$ll.Title=$Title}
170 | if($PSBoundParameters.ContainsKey("Tag")){ $ll.Tag=$Tag}
171 | if($PSBoundParameters.ContainsKey("ContentTypesEnabled")){ $ll.ContentTypesEnabled=$ContentTypesEnabled
172 | }
173 | if($PSBoundParameters.ContainsKey("Description"))
174 | {
175 | $ll.Description=$Description
176 | }
177 | if($PSBoundParameters.ContainsKey("DraftVersionVisibility"))
178 | {
179 | $ll.DraftVersionVisibility=$DraftVersionVisibility
180 | }
181 | if($PSBoundParameters.ContainsKey("EnableAttachments"))
182 | {
183 | $ll.EnableAttachments=$EnableAttachments
184 | }
185 | if($PSBoundParameters.ContainsKey("EnableMinorVersions"))
186 | {$ll.EnableMinorVersions=$EnableMinorVersions}
187 | if($PSBoundParameters.ContainsKey("EnableFolderCreation"))
188 | {$ll.EnableFolderCreation=$EnableFolderCreation}
189 | if($PSBoundParameters.ContainsKey("EnableVersioning"))
190 | {$ll.EnableVersioning=$EnableVersioning}
191 | if($PSBoundParameters.ContainsKey("EnableModeration"))
192 | {$ll.EnableModeration=$EnableModeration}
193 | if($PSBoundParameters.ContainsKey("ForceCheckout"))
194 | {$ll.ForceCheckout=$ForceCheckout}
195 | if($PSBoundParameters.ContainsKey("Hidden"))
196 | {$ll.Hidden=$Hidden}
197 | if($PSBoundParameters.ContainsKey("IRMEnabled"))
198 | {$ll.IRMEnabled=$IRMEnabled}
199 | if($PSBoundParameters.ContainsKey("IsApplicationList"))
200 | {$ll.IsApplicationList=$IsApplicationList}
201 | if($PSBoundParameters.ContainsKey("OnQuickLaunch"))
202 | {$ll.OnQuickLaunch=$OnQuickLaunch}
203 |
204 | $ll.Update()
205 |
206 | try
207 | {
208 | $ctx.ExecuteQuery()
209 | Write-Host "Done" -ForegroundColor Green
210 | }
211 | catch [Net.WebException]
212 | {
213 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
214 | }
215 | }
216 |
217 |
218 | function New-SPOList
219 | {
220 |
221 | <#
222 | .link
223 | http://social.technet.microsoft.com/wiki/contents/articles/32341.sharepoint-online-spomod-new-spolist.aspx
224 |
225 | #>
226 | param (
227 | [Parameter(Mandatory=$true,Position=0)]
228 | [string]$Title,
229 | [Parameter(Mandatory=$false,Position=1)]
230 | [int]$TemplateType=100,
231 | [Parameter(Mandatory=$false,Position=2)]
232 | [string]$Description="",
233 | [Parameter(Mandatory=$false,Position=3)]
234 | [Int]$DocumentTemplateType,
235 | [Parameter(Mandatory=$false,Position=4)]
236 | [GUID]$TemplateFeatureID,
237 | [Parameter(Mandatory=$false,Position=5)]
238 | [string]$ListUrl=""
239 | )
240 |
241 | $ListUrl=$Title
242 |
243 | $lci =New-Object Microsoft.SharePoint.Client.ListCreationInformation
244 | $lci.Description=$Description
245 | $lci.Title=$Title
246 | $lci.Templatetype=$TemplateType
247 | if($PSBoundParameters.ContainsKey("ListUrl"))
248 | {
249 | $lci.Url =$ListUrl
250 | }
251 | if($PSBoundParameters.ContainsKey("DocumentTemplateType"))
252 | {
253 | $lci.DocumentTemplateType=$DocumentTemplateType
254 | }
255 | if($PSBoundParameters.ContainsKey("TemplateFeatureID"))
256 | {
257 | $lci.TemplateFeatureID=$TemplateFeatureID
258 | }
259 | $list = $ctx.Web.Lists.Add($lci)
260 | $ctx.Load($list)
261 |
262 | try
263 | {
264 | $ctx.ExecuteQuery()
265 | Write-Host "List " $Title " has been added. "
266 | }
267 | catch [Net.WebException]
268 | {
269 | Write-Host $_.Exception.ToString()
270 | }
271 |
272 | }
273 |
274 |
275 |
276 | #
277 | # The following cmdlets will be retired, as they are already included in Set-SPOList cmdlet
278 | #
279 |
280 |
281 | function Set-SPOListCheckout
282 | {
283 | param (
284 | [Parameter(Mandatory=$true,Position=1)]
285 | [string]$ListName,
286 | [Parameter(Mandatory=$false,Position=2)]
287 | [bool]$ForceCheckout=$true
288 | )
289 |
290 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
291 | $ll.ForceCheckout = $ForceCheckout
292 | $ll.Update()
293 |
294 | $listurl=$null
295 | if($ctx.Url.EndsWith("/")) {$listurl= $ctx.Url+$ll.Title}
296 | else {$listurl=$ctx.Url+"/"+$ll.Title}
297 | try
298 | {
299 | #$ErrorActionPreference="Stop"
300 | $ctx.ExecuteQuery()
301 | Write-Host "Done!" -ForegroundColor DarkGreen
302 | }
303 |
304 | catch [Net.WebException]
305 | {
306 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
307 | }
308 | }
309 |
310 | function Set-SPOListVersioning
311 | {
312 | param (
313 | [Parameter(Mandatory=$true,Position=1)]
314 | [string]$ListName,
315 | [Parameter(Mandatory=$false,Position=2)]
316 | [bool]$Enabled=$true
317 | )
318 |
319 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
320 | $ll.EnableVersioning=$Enabled
321 | $ll.Update()
322 |
323 |
324 | try
325 | {
326 | $ctx.ExecuteQuery()
327 | Write-Host "Done!" -ForegroundColor DarkGreen
328 | }
329 |
330 | catch [Net.WebException]
331 | {
332 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
333 | }
334 |
335 | }
336 |
337 |
338 | function Set-SPOListMinorVersioning
339 | {
340 | param (
341 | [Parameter(Mandatory=$true,Position=1)]
342 | [string]$ListName,
343 | [Parameter(Mandatory=$false,Position=2)]
344 | [bool]$Enabled=$true
345 | )
346 |
347 |
348 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
349 | $ll.EnableMinorVersions=$Enabled
350 | $ll.Update()
351 |
352 | try
353 | {
354 | $ctx.ExecuteQuery()
355 | Write-Host "Done!" -ForegroundColor DarkGreen
356 | }
357 | catch [Net.WebException]
358 | {
359 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
360 | }
361 |
362 | }
363 |
364 |
365 | function Remove-SPOListInheritance
366 | {
367 | param (
368 | [Parameter(Mandatory=$true,Position=1)]
369 | [string]$ListName,
370 | [Parameter(Mandatory=$false,Position=2)]
371 | [bool]$KeepPermissions=$true
372 | )
373 |
374 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
375 | $ll.BreakRoleInheritance($KeepPermissions, $false)
376 | $ll.Update()
377 |
378 | try
379 | {
380 | $ctx.ExecuteQuery()
381 | Write-Host "Done!" -ForegroundColor DarkGreen
382 | }
383 | catch [Net.WebException]
384 | {
385 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
386 | }
387 |
388 | }
389 |
390 |
391 | function Restore-SPOListInheritance
392 | {
393 | param (
394 | [Parameter(Mandatory=$true,Position=0)]
395 | [string]$ListName
396 | )
397 |
398 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
399 | $ll.ResetRoleInheritance()
400 | $ll.Update()
401 |
402 | try
403 | {
404 | $ctx.ExecuteQuery()
405 | Write-Host "Done!" -ForegroundColor DarkGreen
406 | }
407 |
408 | catch [Net.WebException]
409 | {
410 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
411 | }
412 | }
413 |
414 |
415 | function Set-SPOListContentTypesEnabled
416 | {
417 | param (
418 | [Parameter(Mandatory=$true,Position=0)]
419 | [string]$ListName,
420 | [Parameter(Mandatory=$false,Position=1)]
421 | [bool]$Enabled=$true
422 | )
423 |
424 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
425 | $ll.ContentTypesEnabled=$Enabled
426 | $ll.Update()
427 |
428 | try
429 | {
430 | $ctx.ExecuteQuery()
431 | Write-Host "Done!" -ForegroundColor DarkGreen
432 | }
433 |
434 | catch [Net.WebException]
435 | {
436 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
437 | }
438 | }
439 |
440 |
441 | function Remove-SPOList
442 | {
443 | <#
444 | .link
445 | http://social.technet.microsoft.com/wiki/contents/articles/32362.sharepoint-online-spomod-remove-spolist.aspx
446 |
447 | #>
448 |
449 | param (
450 | [Parameter(Mandatory=$true,Position=0)]
451 | [string]$ListName
452 | )
453 |
454 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
455 | $ll.DeleteObject();
456 |
457 | try
458 | {
459 | $ctx.ExecuteQuery()
460 | Write-Host "Done!" -ForegroundColor DarkGreen
461 | }
462 |
463 | catch [Net.WebException]
464 | {
465 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
466 | }
467 |
468 | }
469 |
470 |
471 | function Set-SPOListFolderCreationEnabled
472 | {
473 | param (
474 | [Parameter(Mandatory=$true,Position=0)]
475 | [string]$ListName,
476 | [Parameter(Mandatory=$false,Position=1)]
477 | [bool]$Enabled=$true
478 | )
479 |
480 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
481 | $ll.EnableFolderCreation=$Enabled
482 | $ll.Update()
483 |
484 | try
485 | {
486 | $ctx.ExecuteQuery()
487 | Write-Host "Done!" -ForegroundColor DarkGreen
488 | }
489 | catch [Net.WebException]
490 | {
491 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
492 | }
493 |
494 | }
495 |
496 |
497 | function Set-SPOListIRMEnabled
498 | {
499 | param (
500 | [Parameter(Mandatory=$true,Position=0)]
501 | [string]$ListName,
502 | [Parameter(Mandatory=$false,Position=1)]
503 | [bool]$Enabled=$true
504 | )
505 |
506 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
507 | $ll.IrmEnabled=$Enabled
508 | $ll.Update()
509 |
510 | try
511 | {
512 | $ctx.ExecuteQuery()
513 | Write-Host "Done!" -ForegroundColor DarkGreen
514 | }
515 | catch [Net.WebException]
516 | {
517 | Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red
518 | }
519 |
520 | }
521 |
522 |
523 | #endregion
524 |
525 | #
526 | #
527 | #
528 | #
529 | #
530 | # View Cmdlets
531 | #
532 | #
533 | #
534 | #
535 | #
536 | #
537 | #
538 |
539 | #region ViewCmdlets
540 |
541 | function Get-SPOListView
542 | {
543 |
544 | <#
545 | .link
546 | http://social.technet.microsoft.com/wiki/contents/articles/32363.sharepoint-online-spomod-get-spolistview.aspx
547 |
548 | #>
549 |
550 |
551 | param (
552 | [Parameter(ParameterSetName="seta", Mandatory=$true,Position=0)]
553 | [string]$ListName="",
554 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
555 | [string]$ListGUID="",
556 | [Parameter(Mandatory=$false,Position=0)]
557 | [switch]$IncludeAllProperties
558 | )
559 |
560 | switch ($PsCmdlet.ParameterSetName)
561 | {
562 | "seta" { $list=$ctx.Web.Lists.GetByTitle($ListName); break}
563 | "setb" { $list=$ctx.Web.Lists.GetByID($ListGUID); break}
564 | }
565 | $ctx.Load($list)
566 | $ctx.Load($list.Views)
567 | $ctx.ExecuteQuery()
568 |
569 | foreach($vv in $list.Views)
570 | {
571 |
572 | if($IncludeAllProperties){
573 | $ctx.Load($vv)
574 | $ctx.Load($vv.ViewFields)
575 | $ctx.ExecuteQuery()
576 | $vv | Add-Member NoteProperty List.Title($ListName)
577 |
578 | Write-Output $vv}
579 | else {Write-Output $vv.Title}
580 | }
581 | }
582 |
583 |
584 |
585 | function Remove-SPOListView
586 | {
587 |
588 | <#
589 | .link
590 | http://social.technet.microsoft.com/wiki/contents/articles/32364.sharepoint-online-spomod-remove-spolistview.aspx
591 |
592 | #>
593 |
594 | param (
595 | [parameter(ParameterSetName="seta",ValueFromPipelineByPropertyName, Mandatory=$true,Position=0)]
596 | [Alias('List.Title')]
597 | [string]$ListName,
598 | [Parameter(ParameterSetName="seta", ValueFromPipelineByPropertyName, Mandatory=$true,Position=0)]
599 | [Alias('Title')]
600 | [string]$ViewName,
601 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
602 | [GUID]$ListGUID,
603 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
604 | [GUID]$ViewGUID
605 | )
606 |
607 | Begin{
608 | }
609 |
610 | Process{
611 | switch ($PsCmdlet.ParameterSetName)
612 | {
613 | "seta" {
614 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
615 | $vv=$ll.Views.GetByTitle($ViewName); break}
616 | "setb" {
617 | $ll=$ctx.Web.Lists.GetByID($ListGUID)
618 | $vv=$ll.Views.GetByID($ViewGUID); break}
619 | }
620 | $ctx.Load($vv)
621 | $ctx.ExecuteQuery()
622 | $vv.DeleteObject()
623 | Write-Verbose "Deleting the view"
624 | $ctx.ExecuteQuery
625 | }
626 | }
627 |
628 |
629 | function Set-SPOListView
630 | {
631 |
632 | <#
633 | .link
634 | http://social.technet.microsoft.com/wiki/contents/articles/32365.sharepoint-online-spomod-set-spolistview.aspx
635 |
636 | #>
637 |
638 |
639 | param (
640 | [Parameter(ParameterSetName="seta", Mandatory=$true,Position=0)]
641 | [string]$ListName="",
642 | [Parameter(ParameterSetName="seta", Mandatory=$true,Position=0)]
643 | [string]$ViewName="",
644 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
645 | [string]$ListGUID="",
646 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
647 | [string]$ViewGUID="",
648 | [Parameter( Mandatory=$false)]
649 | [bool]$Hidden,
650 | [Parameter( Mandatory=$false)]
651 | [bool]$DefaultView,
652 | [Parameter( Mandatory=$false)]
653 | [string]$AggregationsStatus,
654 | [Parameter( Mandatory=$false)]
655 | [string]$Aggregations,
656 | [Parameter( Mandatory=$false)]
657 | [string]$DefaultViewForContentType,
658 | [Parameter( Mandatory=$false)]
659 | [bool]$EditorModfied,
660 | [Parameter( Mandatory=$false)]
661 | [string]$Formats,
662 | [Parameter( Mandatory=$false)]
663 | [bool]$IncludeRootFolder,
664 | [Parameter( Mandatory=$false)]
665 | [string]$JSLink,
666 | [Parameter( Mandatory=$false)]
667 | [bool]$MobileDefaultView,
668 | [Parameter( Mandatory=$false)]
669 | [bool]$MobileView,
670 | [Parameter( Mandatory=$false)]
671 | [bool]$Paged,
672 | [Parameter( Mandatory=$false)]
673 | [bool]$PersonalView,
674 | [Parameter( Mandatory=$false)]
675 | [bool]$RequiresClientIntegration,
676 | [Parameter( Mandatory=$false)]
677 | [bool]$Threaded,
678 | [Parameter( Mandatory=$false)]
679 | [Int]$RowLimit
680 | )
681 |
682 | switch ($PsCmdlet.ParameterSetName)
683 | {
684 | "seta"
685 | {
686 | $ll=$ctx.Web.Lists.GetByTitle($ListName)
687 | $vv=$ll.Views.GetByTitle($ViewName); break
688 | }
689 | "setb"
690 | {
691 | $ll=$ctx.Web.Lists.GetByID($ListGUID)
692 | $vv=$ll.Views.GetByID($ViewGUID); break
693 | }
694 | }
695 | $ctx.Load($vv)
696 | $ctx.ExecuteQuery()
697 | if($PSBoundParameters.ContainsKey("AggregationsStatus"))
698 | {
699 | $vv.AggregationsStatus=$AggregationsStatus
700 | }
701 | if($PSBoundParameters.ContainsKey("DefaultView"))
702 | {
703 | $vv.DefaultView=$DefaultView
704 | }
705 | if($PSBoundParameters.ContainsKey("Hidden"))
706 | {
707 | $vv.Hidden=$Hidden
708 | }
709 | if($PSBoundParameters.ContainsKey("Aggregations"))
710 | {
711 | $vv.Aggregations=$Aggregations
712 | }
713 | if($PSBoundParameters.ContainsKey("DefaultViewForContentType"))
714 | {
715 | $vv.DefaultViewForContentType=$DefaultViewForContentType
716 | }
717 | if($PSBoundParameters.ContainsKey("EditorModfied"))
718 | {
719 | $vv.EditorModified=$EditorModfied
720 | }
721 | if($PSBoundParameters.ContainsKey("Formats"))
722 | {
723 | $vv.Formats=$Formats
724 | }
725 | if($PSBoundParameters.ContainsKey("IncludeRootFolder"))
726 | {
727 | $vv.IncludeRootFolder=$IncludeRootFolder
728 | }
729 | if($PSBoundParameters.ContainsKey("JSLink"))
730 | {
731 | $vv.JSLink=$JSLink
732 | }
733 | if($PSBoundParameters.ContainsKey("MobileDefaultView"))
734 | {
735 | $vv.MobileDefaultView=$MobileDefaultView
736 | }
737 | if($PSBoundParameters.ContainsKey("MobileView"))
738 | {
739 | $vv.MobileView=$MobileView
740 | }
741 |
742 | if($PSBoundParameters.ContainsKey("Paged"))
743 | {
744 | $vv.Paged=$Paged
745 | }
746 | if($PSBoundParameters.ContainsKey("PersonalView"))
747 | {
748 | $vv.PersonalView=$PersonalView
749 | }
750 |
751 | if($PSBoundParameters.ContainsKey("RequiresClientIntegration"))
752 | {
753 | $vv.RequiresClientIntegration=$RequiresClientIntegration
754 | }
755 | if($PSBoundParameters.ContainsKey("Threaded"))
756 | {
757 | $vv.Threaded=$Threaded
758 | }
759 | if($PSBoundParameters.ContainsKey("RowLimit"))
760 | {
761 | $vv.RowLimit=$RowLimit
762 | }
763 |
764 | $vv.Update()
765 | $ctx.ExecuteQuery()
766 | }
767 |
768 |
769 | function New-SPOListView
770 | {
771 |
772 | <#
773 | .link
774 | http://social.technet.microsoft.com/wiki/contents/articles/32366.sharepoint-online-spomod-new-spolistview.aspx
775 |
776 | #>
777 |
778 |
779 |
780 | param (
781 | [Parameter(ParameterSetName="seta", Mandatory=$true,Position=0)]
782 | [string]$ListName="",
783 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=0)]
784 | [string]$ListGUID="",
785 | [Parameter(Mandatory=$true)]
786 | [string]$ViewName="DefaultName",
787 | [Parameter(Mandatory=$false)]
788 | [string]$ViewQuery,
789 | [Parameter(Mandatory=$false)]
790 | [string[]]$ViewFields,
791 | [Parameter(Mandatory=$false)]
792 | [Int]$RowLimit
793 | )
794 |
795 | $Vv = New-Object Microsoft.SharePoint.Client.ViewCreationInformation
796 | $vv.Title=$ViewName
797 | if($PSBoundParameters.ContainsKey("viewQuery"))
798 | {
799 | $vv.Query=$viewQuery
800 | }
801 | if($PSBoundParameters.ContainsKey("RowLimit"))
802 | {
803 | $vv.RowLimit=$RowLimit
804 | }
805 | if($PSBoundParameters.ContainsKey("ViewFields"))
806 | {
807 | $vv.ViewFields=$ViewFields
808 | }
809 |
810 |
811 | switch ($PsCmdlet.ParameterSetName)
812 | {
813 | "seta"
814 | {
815 | $ll=$ctx.Web.Lists.GetByTitle($ListName); break
816 | }
817 | "setb"
818 | {
819 | $ll=$ctx.Web.Lists.GetByID($ListGUID); break
820 | }
821 | }
822 | $ctx.Load($ll)
823 | $ctx.Load($ll.Views)
824 | $ctx.ExecuteQuery()
825 | $listViewToadd=$ll.Views.Add($vv)
826 | $ctx.Load($listViewToadd)
827 | $ctx.ExecuteQuery()
828 | }
829 |
830 |
831 | #endregion
832 |
833 | #
834 | #
835 | #
836 | #
837 | # Column Cmdlets
838 | #
839 | #
840 | #
841 | #
842 | #
843 | #
844 |
845 |
846 | function Get-SPOListColumn
847 | {
848 |
849 | <#
850 | .link
851 | http://social.technet.microsoft.com/wiki/contents/articles/32397.sharepoint-online-spomod-get-spolistcolumn.aspx
852 |
853 | #>
854 |
855 | param (
856 | [Parameter(Mandatory=$true,Position=0)]
857 | [string]$ListTitle,
858 | [Parameter(Mandatory=$true,Position=1)]
859 | [string]$FieldTitle
860 |
861 | )
862 |
863 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
864 |
865 | $ctx.ExecuteQuery()
866 | $Field=$List.Fields.GetByInternalNameOrTitle($FieldTitle)
867 | $ctx.Load($Field)
868 |
869 | try
870 | {
871 | $ctx.ExecuteQuery()
872 |
873 |
874 | $obj = New-Object PSObject
875 | $obj | Add-Member NoteProperty CanBeDeleted($Field.CanBeDeleted)
876 | $obj | Add-Member NoteProperty DefaultValue($Field.DefaultValue)
877 | $obj | Add-Member NoteProperty Description($Field.Description)
878 | $obj | Add-Member NoteProperty Direction($Field.Direction)
879 | $obj | Add-Member NoteProperty EnforceUniqueValues($Field.EnforceUniqueValues)
880 | $obj | Add-Member NoteProperty EntityPropertyName($Field.EntityPropertyName)
881 | $obj | Add-Member NoteProperty Filterable($Field.Filterable)
882 | $obj | Add-Member NoteProperty FromBaseType($Field.FromBaseType)
883 | $obj | Add-Member NoteProperty Group($Field.Group)
884 | $obj | Add-Member NoteProperty Hidden($Field.Hidden)
885 | $obj | Add-Member NoteProperty ID($Field.Id)
886 | $obj | Add-Member NoteProperty Indexed($Field.Indexed)
887 | $obj | Add-Member NoteProperty InternalName($Field.InternalName)
888 | $obj | Add-Member NoteProperty JSLink($Field.JSLink)
889 | $obj | Add-Member NoteProperty ReadOnlyField($Field.ReadOnlyField)
890 | $obj | Add-Member NoteProperty Required($Field.Required)
891 | $obj | Add-Member NoteProperty SchemaXML($Field.SchemaXML)
892 | $obj | Add-Member NoteProperty Scope($Field.Scope)
893 | $obj | Add-Member NoteProperty Sealed($Field.Sealed)
894 | $obj | Add-Member NoteProperty StaticName($Field.StaticName)
895 | $obj | Add-Member NoteProperty Sortable($Field.Sortable)
896 | $obj | Add-Member NoteProperty Tag($Field.Tag)
897 | $obj | Add-Member NoteProperty Title($Field.Title)
898 | $obj | Add-Member NoteProperty FieldType($Field.FieldType)
899 | $obj | Add-Member NoteProperty TypeAsString($Field.UIVersionLabel)
900 | $obj | Add-Member NoteProperty TypeDisplayName($Field.UIVersionLabel)
901 | $obj | Add-Member NoteProperty TypeShortDescription($Field.UIVersionLabel)
902 | $obj | Add-Member NoteProperty ValidationFormula($Field.UIVersionLabel)
903 | $obj | Add-Member NoteProperty ValidationMessage($Field.UIVersionLabel)
904 |
905 |
906 | Write-Output $obj
907 | }
908 | catch [Net.WebException]
909 | {
910 | Write-Host $_.Exception.ToString()
911 | }
912 |
913 | }
914 |
915 |
916 |
917 |
918 |
919 | function New-SPOListColumn
920 | {
921 |
922 | <#
923 | .link
924 | http://social.technet.microsoft.com/wiki/contents/articles/32403.sharepoint-online-spomod-new-spolistcolumn.aspx
925 |
926 | #>
927 |
928 |
929 | param (
930 | [Parameter(Mandatory=$true,Position=0)]
931 | [string]$ListTitle,
932 | [Parameter(Mandatory=$true,Position=1)]
933 | [string]$FieldDisplayName,
934 | [Parameter(Mandatory=$true, Position=2)]
935 | [ValidateSet('AllDayEvent','Attachments','Boolean', 'Calculated', 'Choice', 'Computed', 'ContenttypeID', 'Counter', 'CrossProjectLink', 'Currency', 'DateTime', 'Error', 'File', 'Geolocation', 'GridChoice', 'Guid', 'Integer', 'Invalid', 'Lookup', 'MaxItems', 'ModStat', 'MultiChoice', 'Note', 'Number', 'OutcomeChoice', 'PageSeparator', 'Recurrence', 'Text', 'ThreadIndex', 'Threading', 'Url','User', 'WorkflowEventType', 'WorkflowStatus')]
936 | [System.String]$FieldType,
937 | [Parameter(Mandatory=$false,Position=3)]
938 | [string]$Description="",
939 | [Parameter(Mandatory=$false,Position=4)]
940 | [string]$Required="false",
941 | [Parameter(Mandatory=$false,Position=5)]
942 | [string]$Group="",
943 | [Parameter(Mandatory=$false,Position=6)]
944 | [string]$StaticName,
945 | [Parameter(Mandatory=$false,Position=7)]
946 | [string]$Name,
947 | [Parameter(Mandatory=$false,Position=8)]
948 | [string]$Version="1",
949 | [Parameter(Mandatory=$false,Position=9)]
950 | [bool]$AddToDefaultView=$false,
951 | [Parameter(Mandatory=$false,Position=10)]
952 | [string]$AddToView="",
953 | [Parameter(Mandatory=$false,Position=11)]
954 | [string]$LookupListGUID="",
955 | [Parameter(Mandatory=$false,Position=12)]
956 | [string]$LookupField="Title"
957 | )
958 |
959 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
960 | $ctx.ExecuteQuery()
961 |
962 | if($PSBoundParameters.ContainsKey("StaticName")) {$StaticName=$StaticName}
963 | else {$StaticName=$FieldDisplayName}
964 | if($PSBoundParameters.ContainsKey("Name")) {$Name=$Name}
965 | else {$Name=$FieldDisplayName}
966 |
967 | $FieldOptions=[Microsoft.SharePoint.Client.AddFieldOptions]::AddToAllContentTypes
968 | $xml=""
969 |
970 | if($LookupListGUID)
971 | {
972 | $xml=$xml.Replace(">"," List='"+$LookupListGUID+"' ShowField='"+$LookupField+"'>")
973 | }
974 | Write-Host $xml
975 | $List.Fields.AddFieldAsXml($xml,$true,$FieldOptions)
976 | $List.Update()
977 |
978 | try
979 | {
980 | $ctx.ExecuteQuery()
981 | Write-Host "Field " $FieldDisplayName " has been added to " $ListTitle
982 | }
983 | catch [Net.WebException]
984 | {
985 | Write-Host $_.Exception.ToString()-ForegroundColor Red
986 | }
987 |
988 | if($AddToDefaultView -eq $true)
989 | {
990 | $ctx.Load($List.DefaultView)
991 | $ctx.ExecuteQuery()
992 | if($List.DefaultView -eq $null){ Write-Verbose "There is no default view set for this list"}
993 | $DefaultViewFields=$List.DefaultView.ViewFields
994 | $ctx.Load($DefaultViewFields)
995 | $ctx.ExecuteQuery()
996 | $List.DefaultView.ViewFields.Add($Name)
997 | $List.DefaultView.Update()
998 | $ctx.ExecuteQuery()
999 | Write-Verbose "Adding to the default view"
1000 | }
1001 |
1002 | if($AddToView -ne "")
1003 | {
1004 | $ctx.Load($List.Views)
1005 | $ctx.ExecuteQuery()
1006 | $vv=$List.Views.GetByTitle($AddToView.Trim())
1007 | $ctx.Load($vv)
1008 | $ctx.ExecuteQuery()
1009 | $vv.ViewFields.Add($Name)
1010 | $vv.Update()
1011 | $ctx.ExecuteQuery()
1012 | Write-Verbose "Adding to the view "
1013 | }
1014 |
1015 | }
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 | function Set-SPOListColumn
1023 | {
1024 |
1025 | <#
1026 | .link
1027 | http://social.technet.microsoft.com/wiki/contents/articles/32398.sharepoint-online-spomod-set-spolistcolumn.aspx
1028 |
1029 | #>
1030 |
1031 |
1032 | param (
1033 | [Parameter(Mandatory=$true,Position=0)]
1034 | [string]$ListTitle,
1035 | [Parameter(Mandatory=$false,Position=11)]
1036 | [string]$DefaultValue,
1037 | [Parameter(Mandatory=$false,Position=12)]
1038 | [string]$Description="",
1039 | [Parameter(Mandatory=$false,Position=13)]
1040 | [ValidateSet('LTR','RTL','none')]
1041 | [string]$Direction,
1042 | [Parameter(Mandatory=$false,Position=14)]
1043 | [bool]$EnforceUniqueValues,
1044 | [Parameter(Mandatory=$false,Position=15)]
1045 | [string]$Group="",
1046 | [Parameter(Mandatory=$false,Position=16)]
1047 | [bool]$Hidden,
1048 | [Parameter(Mandatory=$false,Position=17)]
1049 | [bool]$Indexed,
1050 | [Parameter(Mandatory=$false,Position=18)]
1051 | [string]$JSLink="",
1052 | [Parameter(Mandatory=$false,Position=19)]
1053 | [bool]$ReadOnlyField,
1054 | [Parameter(Mandatory=$false,Position=110)]
1055 | [bool]$Required,
1056 | [Parameter(Mandatory=$false,Position=111)]
1057 | [string]$SchemaXML,
1058 | [Parameter(Mandatory=$false,Position=112)]
1059 | [string]$StaticName,
1060 | [Parameter(Mandatory=$false,Position=113)]
1061 | [string]$Tag,
1062 | [Parameter(Mandatory=$true,Position=1)]
1063 | [string]$FieldTitle
1064 | )
1065 |
1066 |
1067 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
1068 | $ctx.ExecuteQuery()
1069 | $lci=$List.Fields.GetByInternalNameOrTitle($FieldTitle)
1070 | $ctx.ExecuteQuery()
1071 |
1072 | if($PSBoundParameters.ContainsKey("Description"))
1073 | {
1074 | $lci.Description=$Description
1075 | }
1076 | if($PSBoundParameters.ContainsKey("DefaultValue"))
1077 | {
1078 | $lci.DefaultValue=$DefaultValue
1079 | }
1080 |
1081 | if($PSBoundParameters.ContainsKey("Direction"))
1082 | {
1083 | $lci.Direction=$Direction
1084 | }
1085 | if($PSBoundParameters.ContainsKey("EnforceUniqueValues"))
1086 | {
1087 | $lci.EnforceUniqueValues=$EnforceUniqueValues
1088 | }
1089 |
1090 | if($PSBoundParameters.ContainsKey("Group"))
1091 | {
1092 | $lci.Group=$Group
1093 | }
1094 | if($PSBoundParameters.ContainsKey("Hidden")){
1095 | $lci.Hidden=$Hidden
1096 | }
1097 | if($PSBoundParameters.ContainsKey("Indexed"))
1098 | {
1099 | $lci.Indexed=$Indexed
1100 | }
1101 |
1102 | if($PSBoundParameters.ContainsKey("JSLink"))
1103 | {
1104 | $lci.JSLink=$JSLink
1105 | }
1106 | if($PSBoundParameters.ContainsKey("ReadOnlyField"))
1107 | {
1108 | $lci.ReadOnlyField=$ReadOnlyField
1109 | }
1110 | if($PSBoundParameters.ContainsKey("Required"))
1111 | {
1112 | $lci.Required=$Required
1113 | }
1114 | if($PSBoundParameters.ContainsKey("SchemaXML"))
1115 | {
1116 | $lci.SchemaXML=$SchemaXML
1117 | }
1118 |
1119 |
1120 | if($PSBoundParameters.ContainsKey("StaticName"))
1121 | {
1122 | $lci.StaticName=$StaticName
1123 | }
1124 |
1125 | if($PSBoundParameters.ContainsKey("Tag"))
1126 | {
1127 | $lci.Tag=$Tag
1128 | }
1129 |
1130 | $lci.Update()
1131 | $ctx.load($lci)
1132 |
1133 | try
1134 | {
1135 | $ctx.ExecuteQuery()
1136 | Write-Host $FieldTitle " has been updated"
1137 | }
1138 | catch [Net.WebException]
1139 | {
1140 | Write-Host $_.Exception.ToString()
1141 | }
1142 |
1143 |
1144 | }
1145 |
1146 |
1147 |
1148 | function Remove-SPOListColumn
1149 | {
1150 |
1151 | <#
1152 | .link
1153 | http://social.technet.microsoft.com/wiki/contents/articles/32475.sharepoint-online-spomod-remove-spolistcolumn.aspx
1154 |
1155 | #>
1156 |
1157 | param (
1158 | [Parameter(Mandatory=$true,Position=0)]
1159 | [string]$ListTitle,
1160 | [Parameter(Mandatory=$false,Position=1)]
1161 | [string]$FieldTitle
1162 |
1163 | )
1164 |
1165 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
1166 | $ctx.ExecuteQuery()
1167 | $Field=$List.Fields.GetByTitle($FieldTitle)
1168 | $ctx.ExecuteQuery()
1169 | $Field.DeleteObject()
1170 | $ctx.ExecuteQuery()
1171 |
1172 | }
1173 |
1174 |
1175 | function Get-SPOListColumnFieldIsObjectPropertyInstantiated
1176 | {
1177 |
1178 | <#
1179 | .link
1180 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1181 |
1182 | #>
1183 |
1184 | param (
1185 | [Parameter(Mandatory=$true,Position=0)]
1186 | [string]$ListTitle,
1187 | [Parameter(Mandatory=$false,Position=1)]
1188 | [string]$FieldTitle,
1189 | [Parameter(Mandatory=$false,Position=2)]
1190 | [string]$FieldID,
1191 | [Parameter(Mandatory=$false,Position=3)]
1192 | [string]$ObjectPropertyName
1193 |
1194 | )
1195 |
1196 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
1197 | $ctx.ExecuteQuery()
1198 |
1199 | if($PSBoundParameters.ContainsKey("FieldTitle"))
1200 | {
1201 | $Field=$List.Fields.GetByInternalNameorTitle($FieldTitle)
1202 | }
1203 | if($PSBoundParameters.ContainsKey("FieldID"))
1204 | {
1205 | $Field=$List.Fields.GetById($FieldID)
1206 | }
1207 |
1208 | $ctx.ExecuteQuery()
1209 | $Field.IsObjectPropertyInstantiated($ObjectPropertyName)
1210 | $ctx.ExecuteQuery()
1211 |
1212 | }
1213 |
1214 |
1215 |
1216 | function Get-SPOListColumnFieldIsPropertyAvailable
1217 | {
1218 |
1219 | <#
1220 | .link
1221 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1222 |
1223 | #>
1224 |
1225 | param (
1226 | [Parameter(Mandatory=$true,Position=0)]
1227 | [string]$ListTitle,
1228 | [Parameter(Mandatory=$false,Position=1)]
1229 | [string]$FieldTitle,
1230 | [Parameter(Mandatory=$false,Position=2)]
1231 | [string]$FieldID,
1232 | [Parameter(Mandatory=$false,Position=3)]
1233 | [string]$PropertyName
1234 |
1235 | )
1236 |
1237 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
1238 | $ctx.ExecuteQuery()
1239 |
1240 | if($PSBoundParameters.ContainsKey("FieldTitle"))
1241 | {
1242 | $Field=$List.Fields.GetByInternalNameorTitle($FieldTitle)
1243 | }
1244 | if($PSBoundParameters.ContainsKey("FieldID"))
1245 | {
1246 | $Field=$List.Fields.GetById($FieldID)
1247 | }
1248 |
1249 | $ctx.ExecuteQuery()
1250 | $Field.IsPropertyAvailable($PropertyName)
1251 | $ctx.ExecuteQuery()
1252 |
1253 | }
1254 |
1255 |
1256 |
1257 | function New-SPOListChoiceColumn
1258 | {
1259 |
1260 | <#
1261 | .link
1262 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1263 |
1264 | #>
1265 |
1266 | param (
1267 | [Parameter(Mandatory=$true,Position=0)]
1268 | [string]$ListTitle,
1269 | [Parameter(Mandatory=$true,Position=1)]
1270 | [string]$FieldDisplayName,
1271 | [parameter(Mandatory=$true, ValueFromPipeline=$true)]
1272 | [String[]]
1273 | $ChoiceNames,
1274 | [Parameter(Mandatory=$false,Position=2)]
1275 | [string]$Description="",
1276 | [Parameter(Mandatory=$false,Position=3)]
1277 | [string]$Required="false",
1278 | [Parameter(Mandatory=$false,Position=4)]
1279 | [ValidateSet('Dropdown','RadioButtons')]
1280 | [string]$Format="Dropdown",
1281 | [Parameter(Mandatory=$false,Position=5)]
1282 | [string]$Group="",
1283 | [Parameter(Mandatory=$true,Position=6)]
1284 | [string]$StaticName,
1285 | [Parameter(Mandatory=$true,Position=7)]
1286 | [string]$Name,
1287 | [Parameter(Mandatory=$false,Position=8)]
1288 | [string]$Version="1",
1289 | [Parameter(Mandatory=$false,Position=9)]
1290 | [ValidateSet('MultiChoice')]
1291 | [string]$Type
1292 |
1293 | )
1294 |
1295 | $List=$ctx.Web.Lists.GetByTitle($ListTitle)
1296 | $ctx.ExecuteQuery()
1297 | $FieldOptions=[Microsoft.SharePoint.Client.AddFieldOptions]::AddToAllContentTypes
1298 | if($PSBoundParameters.ContainsKey("Type"))
1299 | {
1300 | $xml="
1312 | "
1313 |
1314 | foreach($choice in $ChoiceNames)
1315 | {
1316 | $xml+=""+$choice+"
1317 | "
1318 |
1319 | }
1320 |
1321 | $xml+="
1322 | "
1323 |
1324 |
1325 | Write-Host $xml
1326 | $List.Fields.AddFieldAsXml($xml,$true,$FieldOptions)
1327 | $List.Update()
1328 |
1329 | try
1330 | {
1331 |
1332 | $ctx.ExecuteQuery()
1333 | Write-Host "Field " $FieldDisplayName " has been added to " $ListTitle
1334 | }
1335 | catch [Net.WebException]
1336 | {
1337 | Write-Host $_.Exception.ToString() -ForegroundColor
1338 | }
1339 |
1340 | }
1341 |
1342 |
1343 |
1344 | function Get-SPOListFields
1345 | {
1346 |
1347 | <#
1348 | .link
1349 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1350 |
1351 | #>
1352 |
1353 | param (
1354 | [Parameter(Mandatory=$true,Position=3)]
1355 | [string]$ListTitle,
1356 | [Parameter(Mandatory=$false,Position=4)]
1357 | [bool]$IncludeSubsites=$false
1358 | )
1359 |
1360 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1361 | $ctx.Load($ll)
1362 | $ctx.Load($ll.Fields)
1363 | $ctx.ExecuteQuery()
1364 |
1365 |
1366 | $fieldsArray=@()
1367 | $fieldslist=@()
1368 | foreach ($fiel in $ll.Fields)
1369 | {
1370 | #Write-Host $fiel.Description `t $fiel.EntityPropertyName `t $fiel.Id `t $fiel.InternalName `t $fiel.StaticName `t $fiel.Tag `t $fiel.Title `t $fiel.TypeDisplayName
1371 |
1372 | $array=@()
1373 | $array+="InternalName"
1374 | $array+="StaticName"
1375 | $array+="Title"
1376 | $array+="SchemaXML"
1377 |
1378 | $obj = New-Object PSObject
1379 | $obj | Add-Member NoteProperty $array[0]($fiel.InternalName)
1380 | $obj | Add-Member NoteProperty $array[1]($fiel.StaticName)
1381 | $obj | Add-Member NoteProperty $array[2]($fiel.Title)
1382 | $obj | Add-Member NoteProperty $array[3]($fiel.SchemaXML)
1383 | $fieldsArray+=$obj
1384 | $fieldslist+=$fiel.InternalName
1385 | Write-Output $obj
1386 | }
1387 |
1388 |
1389 | $ctx.Dispose()
1390 | return $fieldsArray
1391 |
1392 | }
1393 |
1394 |
1395 |
1396 | function Get-SPOListItems
1397 | {
1398 | <#
1399 | .link
1400 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1401 |
1402 | #>
1403 |
1404 | param (
1405 | [Parameter(Mandatory=$true,Position=0)]
1406 | [string]$ListTitle,
1407 | [Parameter(Mandatory=$false,Position=1)]
1408 | [bool]$IncludeAllProperties=$false,
1409 | [switch]$Recursive
1410 | )
1411 |
1412 |
1413 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1414 | $ctx.Load($ll)
1415 | $ctx.Load($ll.Fields)
1416 | $ctx.ExecuteQuery()
1417 | $i=0
1418 | $NumberOfItemsInTheList=$ll.ItemCount
1419 | $itemki=@()
1420 | $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
1421 |
1422 | if($Recursive)
1423 | {
1424 | $spqQuery.ViewXml ="";
1425 | }
1426 |
1427 | if($NumberOfItemsInTheList -gt 5000)
1428 | {
1429 | [decimal]$NoOfRuns=($NumberOfItemsInTheList/5000)
1430 | $NoOfRuns=[math]::Ceiling($NoOfRuns)
1431 | $WhichRun = 0
1432 | $NoOfRunsWithoutResults=0;
1433 |
1434 | do
1435 | {
1436 | $startIndex=$WhichRun*5000
1437 | $endIndex=$startIndex+5000
1438 | if($Recursive)
1439 | {
1440 | $spqQuery.ViewXml=""+
1441 | ""+$startIndex+""+
1442 | ""+$endIndex+""+
1443 | ""
1444 | }
1445 | else
1446 | {
1447 | $spqQuery.ViewXml=""+
1448 | ""+$startIndex+""+
1449 | ""+$endIndex+""+
1450 | ""
1451 | }
1452 |
1453 |
1454 |
1455 | # Write-Host $spqQuery.ViewXml
1456 | $partialItems=$ll.GetItems($spqQuery)
1457 | $ctx.Load($partialItems)
1458 | $ctx.ExecuteQuery()
1459 |
1460 | foreach($partialItem in $partialItems)
1461 | {
1462 | $itemki+=$partialItem
1463 | }
1464 |
1465 | # ugly hack to escape infinite loop in case of non-recursive
1466 | if(!$Recursive -and ($partialItems.Count -eq 0))
1467 | {
1468 | $NoOfRunsWithoutResults++;
1469 |
1470 | # if the query by ID did not find any results x times, end the loop
1471 | if($NoOfRunsWithoutResults -eq 5)
1472 | {
1473 | $NumberOfItemsInTheList = 0;
1474 | }
1475 | }
1476 |
1477 | }
1478 | while($itemki.Count -lt $NumberOfItemsInTheList)
1479 |
1480 |
1481 | }
1482 | else
1483 | {
1484 | $itemki=$ll.GetItems($spqQuery)
1485 | $ctx.Load($itemki)
1486 | $ctx.ExecuteQuery()
1487 | }
1488 |
1489 |
1490 | #$spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
1491 | # $spqQuery.ViewAttributes = "Scope='Recursive'"
1492 |
1493 | Write-Verbose ("Items are ready. Retrieving their properties. It may take a while. My tests indicate 30min per 25 000 items. "+ $itemki.Count)
1494 |
1495 | $bobo=Get-SPOListFields -ListTitle $ListTitle
1496 |
1497 |
1498 | $objArray=@()
1499 |
1500 | for($j=0;$j -lt $itemki.Count ;$j++)
1501 | {
1502 |
1503 | $obj = New-Object PSObject
1504 |
1505 | if($IncludeAllProperties)
1506 | {
1507 |
1508 | for($k=0;$k -lt $bobo.Count ; $k++)
1509 | {
1510 |
1511 | # Write-Host $k
1512 | $name=$bobo[$k].InternalName
1513 | $value=$itemki[$j][$name]
1514 | # Write-Host $bobo[$k].SchemaXML
1515 | if($bobo[$k].SchemaXML.Contains('Field Type="Lookup"'))
1516 | {
1517 | Write-Host "Contains lookup"
1518 | $value=$itemki[$j][$name].LookupValue
1519 | }
1520 | if($bobo[$k].SchemaXML.Contains('V3Comments'))
1521 | {
1522 | Write-Host "Contains V3Comments"
1523 | $value=$itemki[$j][$name][0]+$itemki[$j][$name][1]+" bb "+$itemki[$j][$name][2]+$itemki[$j][$name][3]+$itemki[$j][$name][4]
1524 | }
1525 | $obj | Add-Member NoteProperty $name($value) -Force
1526 |
1527 | }
1528 |
1529 | }
1530 | else
1531 | {
1532 | $obj | Add-Member NoteProperty ID($itemki[$j]["ID"])
1533 | $obj | Add-Member NoteProperty Title($itemki[$j]["Title"])
1534 |
1535 | }
1536 |
1537 | # Write-Host $obj.ID `t $obj.Title
1538 | $objArray+=$obj
1539 |
1540 | }
1541 |
1542 |
1543 | return $objArray
1544 |
1545 |
1546 | }
1547 |
1548 |
1549 |
1550 | function Get-SPOListItemVersions
1551 | {
1552 | param([Parameter(Mandatory=$true,Position=0)]
1553 | [string]$ListTitle,
1554 | [Parameter(Mandatory=$true,Position=1)]
1555 | [int]$ItemID=0,
1556 | [Parameter(Mandatory=$false,Position=2)]
1557 | [bool]$IncludeAllProperties=$false)
1558 |
1559 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1560 | $item=$ll.GetItemByID($ItemID)
1561 | $ctx.Load($item)
1562 | $ctx.ExecuteQuery()
1563 |
1564 | Write-Host $item["FileRef"]
1565 | $file =$ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
1566 | $ctx.Load($file)
1567 | $ctx.Load($file.Versions)
1568 |
1569 | try{
1570 | $ctx.ExecuteQuery() }
1571 | catch
1572 | {
1573 |
1574 | }
1575 | if($file.Versions.Count -eq 0)
1576 | {
1577 | Write-Output "No versions available"
1578 | }
1579 | else{
1580 | foreach($vers in $file.Versions)
1581 | {
1582 | Write-Output $vers
1583 | }
1584 | }
1585 | }
1586 | #
1587 | #
1588 | #
1589 | #
1590 | #
1591 | #
1592 | #
1593 | #
1594 | #
1595 | # Item Cmdlets
1596 | #
1597 | #
1598 | #
1599 | #
1600 | #
1601 | #
1602 | #
1603 | #
1604 | #
1605 | #
1606 | #
1607 | #
1608 |
1609 |
1610 |
1611 |
1612 |
1613 |
1614 |
1615 | function New-SPOListItem
1616 | {
1617 |
1618 | <#
1619 | .link
1620 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1621 |
1622 | #>
1623 |
1624 | param (
1625 | [Parameter(Mandatory=$true,Position=0)]
1626 | [string]$ListTitle,
1627 | [Parameter(Mandatory=$true,Position=1)]
1628 | [string]$ItemTitle,
1629 | [Parameter(Mandatory=$false,Position=2)]
1630 | [string]$FolderUrl,
1631 | [Parameter(Mandatory=$false,Position=3)]
1632 | $AdditionalMultipleFields="",
1633 | [Parameter(Mandatory=$false,Position=4)]
1634 | [string]$AdditionalValue="",
1635 | [Parameter(Mandatory=$false)]
1636 | [string]$AdditionalField=""
1637 | )
1638 |
1639 |
1640 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1641 | $ctx.Load($ll)
1642 | $ctx.ExecuteQuery()
1643 |
1644 | $lici =New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
1645 | $lici.FolderUrl=$FolderUrl
1646 |
1647 | $listItem = $ll.AddItem($lici)
1648 | $listItem["Title"]=$ItemTitle
1649 | if($AdditionalField -ne "")
1650 | {
1651 | $listItem[$AdditionalField]=$AdditionalValue
1652 | }
1653 |
1654 | # The following function I owe to Loic Michel. Thanks!
1655 | if($AdditionalMultipleFields -ne "")
1656 | {
1657 | $additionalMultipleFields |%{
1658 | write-verbose "fieldname : $($_.fieldname), fieldvalue $($_.fieldvalue)"
1659 | $listItem[$_.fieldname]=$_.fieldvalue
1660 | }
1661 | }
1662 |
1663 | $listItem.Update()
1664 | $ll.Update()
1665 |
1666 | try
1667 | {
1668 | $ctx.ExecuteQuery()
1669 | Write-Host "Item " $ItemTitle " has been added to list " $ListTitle
1670 | }
1671 | catch [Net.WebException]
1672 | {
1673 | Write-Host $_.Exception.ToString()
1674 | }
1675 |
1676 | }
1677 |
1678 |
1679 |
1680 | function Remove-SPOListItemInheritance
1681 | {
1682 | <#
1683 | .link
1684 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1685 |
1686 | #>
1687 |
1688 |
1689 | param (
1690 | [Parameter(Mandatory=$true,Position=0)]
1691 | [string]$ListTitle,
1692 | [Parameter(Mandatory=$true,Position=1)]
1693 | [Int]$ItemID,
1694 | [Parameter(Mandatory=$true,Position=2)]
1695 | [bool]$KeepPermissions
1696 | )
1697 |
1698 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1699 | $ctx.Load($ll)
1700 | $ctx.ExecuteQuery()
1701 |
1702 |
1703 | $itemek=$ll.GetItemByID($ItemID)
1704 | $ctx.Load($itemek)
1705 | $ctx.ExecuteQuery()
1706 | $itemek.BreakRoleInheritance($KeepPermissions, $false)
1707 | try
1708 | {
1709 | $ctx.ExecuteQuery()
1710 | write-host $itemek.Name " Success"
1711 | }
1712 | catch [Net.WebException]
1713 | {
1714 | Write-Host $_.Exception.ToString()
1715 | }
1716 |
1717 |
1718 | }
1719 |
1720 | <# Deprecated
1721 | function Remove-SPOListItemPermissions
1722 | {
1723 |
1724 | param (
1725 | [Parameter(Mandatory=$true,Position=0)]
1726 | [string]$ListTitle,
1727 | [Parameter(Mandatory=$true,Position=1)]
1728 | [Int]$ItemID
1729 | )
1730 |
1731 |
1732 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1733 | $ctx.Load($ll)
1734 | $ctx.ExecuteQuery()
1735 |
1736 |
1737 | $itemek=$ll.GetItemByID($ItemID)
1738 | $ctx.Load($itemek)
1739 | $ctx.ExecuteQuery()
1740 | $itemek.BreakRoleInheritance($false, $false)
1741 | try
1742 | {
1743 | $ctx.ExecuteQuery()
1744 | write-host $itemek.Name " Success"
1745 | }
1746 | catch [Net.WebException]
1747 | {
1748 | Write-Host $_.Exception.ToString()
1749 | }
1750 |
1751 |
1752 | }
1753 | #>
1754 |
1755 | function Restore-SPOListItemInheritance
1756 | {
1757 | <#
1758 | .link
1759 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1760 |
1761 | #>
1762 |
1763 | param (
1764 | [Parameter(Mandatory=$true,Position=0)]
1765 | [string]$ListTitle,
1766 | [Parameter(Mandatory=$true,Position=1)]
1767 | [Int]$ItemID
1768 | )
1769 |
1770 |
1771 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1772 | $ctx.Load($ll)
1773 | $ctx.ExecuteQuery()
1774 |
1775 |
1776 | $itemek=$ll.GetItemByID($ItemID)
1777 | $ctx.Load($itemek)
1778 | $ctx.ExecuteQuery()
1779 | $itemek.ResetRoleInheritance()
1780 | try
1781 | {
1782 | $ctx.ExecuteQuery()
1783 | write-host $itemek.Name " Success"
1784 | }
1785 | catch [Net.WebException]
1786 | {
1787 | Write-Host $_.Exception.ToString()
1788 | }
1789 |
1790 |
1791 | }
1792 |
1793 | function Remove-SPOListItem
1794 | {
1795 | <#
1796 | .link
1797 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1798 |
1799 | #>
1800 |
1801 |
1802 | param (
1803 | [Parameter(Mandatory=$true,Position=0)]
1804 | [string]$ListTitle,
1805 | [Parameter(Mandatory=$true,Position=1)]
1806 | [Int]$ItemID
1807 | )
1808 |
1809 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1810 | $ctx.Load($ll)
1811 | $ctx.ExecuteQuery()
1812 |
1813 |
1814 | $itemek=$ll.GetItemByID($ItemID)
1815 | $ctx.Load($itemek)
1816 | $ctx.ExecuteQuery()
1817 | $itemek.DeleteObject()
1818 | try
1819 | {
1820 | $ctx.ExecuteQuery()
1821 | write-host $itemek.Name " Success"
1822 | }
1823 | catch [Net.WebException]
1824 | {
1825 | Write-Host $_.Exception.ToString()
1826 | }
1827 |
1828 | }
1829 |
1830 |
1831 |
1832 |
1833 | function Set-SPOListItem
1834 | {
1835 | <#
1836 | .link
1837 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1838 |
1839 | #>
1840 |
1841 |
1842 | param (
1843 | [Parameter(Mandatory=$true,Position=4)]
1844 | [string]$ListTitle,
1845 | [Parameter(Mandatory=$true,Position=5)]
1846 | [Int]$ItemID,
1847 | [Parameter(Mandatory=$true,Position=6)]
1848 | [string]$FieldToUpdate,
1849 | [Parameter(Mandatory=$true,Position=7)]
1850 | [string]$ValueToUpdate
1851 | )
1852 |
1853 |
1854 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
1855 | $ctx.Load($ll)
1856 | $ctx.ExecuteQuery()
1857 |
1858 |
1859 | $itemek=$ll.GetItemByID($ItemID)
1860 | $ctx.Load($itemek)
1861 | $ctx.ExecuteQuery()
1862 | $itemek[$FieldToUpdate] = $ValueToUpdate
1863 | $itemek.Update()
1864 | try
1865 | {
1866 | $ctx.ExecuteQuery()
1867 | write-host $itemek.Name " Success"
1868 | }
1869 | catch [Net.WebException]
1870 | {
1871 | Write-Host $_.Exception.ToString()
1872 | }
1873 |
1874 | }
1875 |
1876 |
1877 |
1878 |
1879 |
1880 |
1881 |
1882 | #
1883 | #
1884 | #
1885 | #
1886 | #
1887 | #
1888 | #
1889 | #
1890 | #
1891 | # File Cmdlets
1892 | #
1893 | #
1894 | #
1895 | #
1896 | #
1897 | #
1898 | #
1899 | #
1900 | #
1901 | #
1902 | #
1903 | #
1904 |
1905 |
1906 |
1907 |
1908 | function Set-SPOFileCheckout
1909 | {
1910 |
1911 | <#
1912 | .link
1913 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1914 |
1915 | #>
1916 | param (
1917 | [Parameter(Mandatory=$true,Position=0)]
1918 | [string]$ServerRelativeUrl
1919 | )
1920 |
1921 |
1922 | $file =
1923 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
1924 | $ctx.Load($file)
1925 | $ctx.ExecuteQuery()
1926 |
1927 | $file.CheckOut()
1928 | $ctx.Load($file)
1929 | try
1930 | {
1931 | $ctx.ExecuteQuery()
1932 |
1933 | Write-Host $file.Name " has been checked out" -ForegroundColor DarkGreen
1934 | }
1935 | catch [Net.WebException]
1936 | {
1937 | Write-Host $_.Exception.ToString()
1938 | }
1939 |
1940 | }
1941 |
1942 |
1943 |
1944 | function Approve-SPOFile
1945 | {
1946 |
1947 | <#
1948 | .link
1949 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1950 |
1951 | #>
1952 |
1953 | param (
1954 | [Parameter(Mandatory=$true,Position=0)]
1955 | [string]$ServerRelativeUrl,
1956 | [Parameter(Mandatory=$false,Position=1)]
1957 | [string]$ApprovalComment=""
1958 | )
1959 |
1960 |
1961 | $file =
1962 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
1963 | $ctx.Load($file)
1964 | $ctx.ExecuteQuery()
1965 |
1966 | $file.Approve($ApprovalComment)
1967 | $ctx.Load($file)
1968 |
1969 | try
1970 | {
1971 | $ctx.ExecuteQuery()
1972 |
1973 |
1974 | Write-Host $file.Name " has been approved" -ForegroundColor DarkGreen
1975 | }
1976 | catch [Net.WebException]
1977 | {
1978 | Write-Host $_.Exception.ToString()
1979 | }
1980 | }
1981 |
1982 |
1983 |
1984 | function Set-SPOFileCheckin
1985 | {
1986 |
1987 | <#
1988 | .link
1989 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
1990 |
1991 | #>
1992 |
1993 |
1994 | param (
1995 | [Parameter(Mandatory=$true,Position=4)]
1996 | [string]$ServerRelativeUrl,
1997 | [Parameter(Mandatory=$true,Position=5)]
1998 | [ValidateSet('MajorCheckIn','MinorCheckIn','OverwriteCheckIn')]
1999 | [System.String]$CheckInType,
2000 | [Parameter(Mandatory=$false,Position=6)]
2001 | [string]$CheckinComment=""
2002 | )
2003 |
2004 |
2005 | $file =
2006 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2007 | $ctx.Load($file)
2008 | $ctx.ExecuteQuery()
2009 |
2010 | $file.CheckIn($CheckInComment, $CheckInType)
2011 | $ctx.Load($file)
2012 | try
2013 | {
2014 | $ctx.ExecuteQuery()
2015 | Write-Host $file.Name " has been checked in" -ForegroundColor DarkGreen
2016 | }
2017 | catch [Net.WebException]
2018 | {
2019 | Write-Host $_.Exception.ToString()
2020 | }
2021 |
2022 | }
2023 |
2024 |
2025 |
2026 |
2027 | function Copy-SPOFile
2028 | {
2029 |
2030 | <#
2031 | .link
2032 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2033 |
2034 | #>
2035 |
2036 | param (
2037 | [Parameter(Mandatory=$true,Position=4)]
2038 | [string]$ServerRelativeUrl,
2039 | [Parameter(Mandatory=$true,Position=5)]
2040 | [string]$DestinationLibrary,
2041 | [Parameter(Mandatory=$false,Position=6)]
2042 | [bool]$Overwrite=$true,
2043 | [Parameter(Mandatory=$false,Position=7)]
2044 | [string]$NewName=""
2045 |
2046 | )
2047 |
2048 |
2049 | $file =
2050 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2051 | $ctx.Load($file)
2052 | $ctx.ExecuteQuery()
2053 |
2054 | if($NewName -eq "")
2055 | {
2056 | $NewName=$file.Name
2057 |
2058 | }
2059 |
2060 | if($DestinationLibrary.EndsWith("/")){}
2061 | else {$DestinationLibrary=$DestinationLibrary+"/"}
2062 |
2063 | $file.CopyTo($DestinationLibrary+$NewName, $Overwrite)
2064 | try
2065 | {
2066 | $ctx.ExecuteQuery()
2067 |
2068 | Write-Host $file.Name " has been copied to" $DestinationLibrary -ForegroundColor DarkGreen
2069 | }
2070 | catch [Net.WebException]
2071 | {
2072 | Write-Host $_.Exception.ToString()
2073 | }
2074 | }
2075 |
2076 |
2077 |
2078 | function Remove-SPOFile
2079 | {
2080 |
2081 | <#
2082 | .link
2083 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2084 |
2085 | #>
2086 |
2087 | param (
2088 | [Parameter(Mandatory=$true,Position=0)]
2089 | [string]$ServerRelativeUrl
2090 | )
2091 |
2092 |
2093 | $file =
2094 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2095 | $ctx.Load($file)
2096 | $ctx.ExecuteQuery()
2097 |
2098 | $file.DeleteObject()
2099 | try
2100 | {
2101 | $ctx.ExecuteQuery()
2102 |
2103 | Write-Host $file.Name " has been deleted" -ForegroundColor DarkGreen
2104 | }
2105 | catch [Net.WebException]
2106 | {
2107 | Write-Host $_.Exception.ToString()
2108 | }
2109 | }
2110 |
2111 |
2112 |
2113 |
2114 | function Deny-SPOFileApproval
2115 | {
2116 |
2117 | <#
2118 | .link
2119 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2120 |
2121 | #>
2122 |
2123 | param (
2124 | [Parameter(Mandatory=$true,Position=0)]
2125 | [string]$ServerRelativeUrl,
2126 | [Parameter(Mandatory=$false,Position=1)]
2127 | [string]$ApprovalComment=""
2128 | )
2129 |
2130 |
2131 | $file =
2132 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2133 | $ctx.Load($file)
2134 | $ctx.ExecuteQuery()
2135 |
2136 | $file.Deny($ApprovalComment)
2137 | $ctx.Load($file)
2138 |
2139 | try
2140 | {
2141 | $ctx.ExecuteQuery()
2142 |
2143 |
2144 | Write-Host $file.Name " has been denied" -ForegroundColor DarkGreen
2145 | }
2146 | catch [Net.WebException]
2147 | {
2148 | Write-Host $_.Exception.ToString()
2149 | }
2150 | }
2151 |
2152 |
2153 |
2154 | function Get-SPOFileIsPropertyAvailable
2155 | {
2156 |
2157 | <#
2158 | .link
2159 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2160 |
2161 | #>
2162 | param (
2163 | [Parameter(Mandatory=$true,Position=0)]
2164 | [string]$ServerRelativeUrl,
2165 | [Parameter(Mandatory=$true,Position=1)]
2166 | [string]$propertyName
2167 | )
2168 |
2169 |
2170 | $file =
2171 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2172 | $ctx.Load($file)
2173 | $ctx.ExecuteQuery()
2174 |
2175 | if($file.IsPropertyAvailable($propertyName))
2176 | {
2177 | Write-Host "True"
2178 | }
2179 | else
2180 | {
2181 | Write-Host "False"
2182 | }
2183 |
2184 | }
2185 |
2186 |
2187 | function Move-SPOFile
2188 | {
2189 |
2190 | <#
2191 | .link
2192 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2193 |
2194 | #>
2195 | param (
2196 | [Parameter(Mandatory=$true,Position=0)]
2197 | [string]$ServerRelativeUrl,
2198 | [Parameter(Mandatory=$true,Position=1)]
2199 | [string]$DestinationLibrary,
2200 | [Parameter(Mandatory=$false,Position=2)]
2201 | [bool]$Overwrite=$false,
2202 | [Parameter(Mandatory=$false,Position=3)]
2203 | [string]$NewName=""
2204 | )
2205 |
2206 |
2207 |
2208 | $file =
2209 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2210 | $ctx.Load($file)
2211 | $ctx.ExecuteQuery()
2212 |
2213 | if($PSBoundParameters.ContainsKey("NewName"))
2214 | {
2215 | $DestinationLibrary+=$NewName
2216 |
2217 | }
2218 | else
2219 | {
2220 | $DestinationLibrary+=$file.Name
2221 |
2222 | }
2223 |
2224 | if($PSBoundParameters.ContainsKey("Overwrite"))
2225 | {
2226 |
2227 | $file.MoveTo($DestinationLibrary,"Overwrite")
2228 | }
2229 | else
2230 | {
2231 | $file.MoveTo($DestinationLibrary,"none")
2232 | }
2233 |
2234 | try
2235 | {
2236 | $ctx.ExecuteQuery()
2237 |
2238 | Write-Host $file.Name " has been moved to " $DestinationLibrary -ForegroundColor DarkGreen
2239 | }
2240 | catch [Net.WebException]
2241 | {
2242 | Write-Host $_.Exception.ToString()
2243 | }
2244 |
2245 | }
2246 |
2247 |
2248 |
2249 | function Publish-SPOFile
2250 | {
2251 |
2252 | <#
2253 | .link
2254 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2255 |
2256 | #>
2257 | param (
2258 | [Parameter(Mandatory=$true,Position=4)]
2259 | [string]$ServerRelativeUrl,
2260 | [Parameter(Mandatory=$false,Position=5)]
2261 | [string]$Comment=""
2262 | )
2263 |
2264 |
2265 | $file =
2266 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2267 | $ctx.Load($file)
2268 | $ctx.ExecuteQuery()
2269 |
2270 | $file.Publish($Comment)
2271 | $ctx.Load($file)
2272 |
2273 | try
2274 | {
2275 | $ctx.ExecuteQuery()
2276 | Write-Host $file.Name " has been published" -ForegroundColor DarkGreen
2277 | }
2278 | catch [Net.WebException]
2279 | {
2280 | Write-Host $_.Exception.ToString()
2281 | }
2282 | }
2283 |
2284 |
2285 |
2286 | function Undo-SPOFileCheckout
2287 | {
2288 |
2289 | <#
2290 | .link
2291 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2292 |
2293 | #>
2294 |
2295 | param (
2296 | [Parameter(Mandatory=$true,Position=0)]
2297 | [string]$ServerRelativeUrl
2298 | )
2299 |
2300 | $file =
2301 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2302 | $ctx.Load($file)
2303 | $ctx.ExecuteQuery()
2304 |
2305 | $file.UndoCheckOut()
2306 | $ctx.Load($file)
2307 | try
2308 | {
2309 | $ctx.ExecuteQuery()
2310 |
2311 | Write-Host "Checkout for " $file.Name " has been undone" -ForegroundColor DarkGreen
2312 | }
2313 | catch [Net.WebException]
2314 | {
2315 | Write-Host $_.Exception.ToString()
2316 | }
2317 |
2318 | }
2319 |
2320 |
2321 | function Undo-SPOFilePublish
2322 | {
2323 | <#
2324 | .link
2325 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2326 |
2327 | #>
2328 | param (
2329 | [Parameter(Mandatory=$true,Position=0)]
2330 | [string]$ServerRelativeUrl,
2331 | [Parameter(Mandatory=$false,Position=1)]
2332 | [string]$Comment
2333 | )
2334 |
2335 |
2336 | $file =
2337 | $ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2338 | $ctx.Load($file)
2339 | $ctx.ExecuteQuery()
2340 |
2341 | $file.Unpublish($Comment)
2342 | $ctx.Load($file)
2343 | try
2344 | {
2345 | $ctx.ExecuteQuery()
2346 |
2347 | Write-Host $file.Name " has been unpublished" -ForegroundColor DarkGreen
2348 | }
2349 | catch [Net.WebException]
2350 | {
2351 | Write-Host $_.Exception.ToString()
2352 | }
2353 |
2354 | }
2355 |
2356 |
2357 |
2358 | function Get-SPOFolderFilesCount
2359 | {
2360 | <#
2361 | .link
2362 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2363 |
2364 | #>
2365 |
2366 | param (
2367 | [Parameter(Mandatory=$true,Position=0)]
2368 | [string]$ServerRelativeUrl
2369 | )
2370 |
2371 |
2372 | $fileCollection =
2373 | $ctx.Web.GetFolderByServerRelativeUrl($ServerRelativeUrl).Files;
2374 | $ctx.Load($fileCollection)
2375 | $ctx.ExecuteQuery()
2376 |
2377 |
2378 | return $fileCollection.Count
2379 |
2380 | }
2381 |
2382 |
2383 |
2384 |
2385 | function Get-SPOFolderFiles
2386 | {
2387 |
2388 | <#
2389 | .link
2390 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2391 |
2392 | #>
2393 |
2394 | param (
2395 | [Parameter(Mandatory=$true,Position=0)]
2396 | [string]$ServerRelativeUrl
2397 | )
2398 |
2399 |
2400 |
2401 | $fileCollection =
2402 | $ctx.Web.GetFolderByServerRelativeUrl($ServerRelativeUrl).Files;
2403 | $ctx.Load($fileCollection)
2404 | $ctx.ExecuteQuery()
2405 |
2406 |
2407 | foreach ($file in $fileCollection)
2408 | {
2409 |
2410 | $ctx.Load($file.ListItemAllFields)
2411 | $Author=$file.Author
2412 | $CheckedOutByUser=$file.CheckedOutByUser
2413 | $LockedByUser=$file.LockedByUser
2414 | $ModifiedBy=$file.ModifiedBy
2415 | $ctx.Load($Author)
2416 | $ctx.Load($CheckedOutByUser)
2417 | $ctx.Load($LockedByUser)
2418 | $ctx.Load($ModifiedBy)
2419 | $ctx.ExecuteQuery()
2420 |
2421 |
2422 | $obj = New-Object PSObject
2423 | $obj | Add-Member NoteProperty Name($file.Name)
2424 | $obj | Add-Member NoteProperty Author.LoginName($file.Author.LoginName)
2425 | $obj | Add-Member NoteProperty CheckedOutByUser.LoginName($file.CheckedOutByUser.LoginName)
2426 | $obj | Add-Member NoteProperty CheckinComment($file.CheckinComment)
2427 | $obj | Add-Member NoteProperty ContentTag($file.ContentTag)
2428 | $obj | Add-Member NoteProperty ETag($file.ETag)
2429 | $obj | Add-Member NoteProperty Exists($file.Exists)
2430 | $obj | Add-Member NoteProperty Length($file.Length)
2431 | $obj | Add-Member NoteProperty LockedByUser.LoginName($file.LockedByUser.LoginName)
2432 | $obj | Add-Member NoteProperty MajorVersion($file.MajorVersion)
2433 | $obj | Add-Member NoteProperty MinorVersion($file.MinorVersion)
2434 | $obj | Add-Member NoteProperty ModifiedBy.LoginName($file.ModifiedBy.LoginName)
2435 | $obj | Add-Member NoteProperty ServerRelativeUrl($file.ServerRelativeUrl)
2436 | $obj | Add-Member NoteProperty Tag($file.Tag)
2437 | $obj | Add-Member NoteProperty TimeCreated($file.TimeCreated)
2438 | $obj | Add-Member NoteProperty TimeLastModified($file.TimeLastModified)
2439 | $obj | Add-Member NoteProperty Title($file.Title)
2440 | $obj | Add-Member NoteProperty UIVersion($file.UIVersion)
2441 | $obj | Add-Member NoteProperty UIVersionLabel($file.UIVersionLabel)
2442 |
2443 |
2444 | Write-Output $obj
2445 | }
2446 |
2447 |
2448 |
2449 | }
2450 |
2451 |
2452 |
2453 | function Get-SPOFileByServerRelativeUrl
2454 | {
2455 |
2456 | <#
2457 | .link
2458 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2459 |
2460 | #>
2461 |
2462 | param (
2463 | [Parameter(Mandatory=$true,Position=0)]
2464 | [string]$ServerRelativeUrl
2465 | )
2466 |
2467 |
2468 | $file =$ctx.Web.GetFileByServerRelativeUrl($ServerRelativeUrl);
2469 | $ctx.Load($file)
2470 | $ctx.ExecuteQuery()
2471 | $Author=$file.Author
2472 |
2473 | $CheckedOutByUser=$file.CheckedOutByUser
2474 | $LockedByUser=$file.LockedByUser
2475 | $ModifiedBy=$file.ModifiedBy
2476 | $ctx.Load($Author)
2477 | $ctx.Load($CheckedOutByUser)
2478 | $ctx.Load($LockedByUser)
2479 | $ctx.Load($ModifiedBy)
2480 | $ctx.Load($file.EffectiveInformationRightsManagementSettings)
2481 | $ctx.Load($file.InformationRightsManagementSettings)
2482 | $ctx.Load($file.ListItemAllFields)
2483 | $ctx.Load($file.Properties)
2484 | $ctx.Load($file.VersionEvents)
2485 | $ctx.Load($file.Versions)
2486 | $ctx.ExecuteQuery()
2487 | <#
2488 | $obj = New-Object PSObject
2489 | $obj | Add-Member NoteProperty Name($file.Name)
2490 | $obj | Add-Member NoteProperty Author.LoginName($file.Author.LoginName)
2491 | $obj | Add-Member NoteProperty CheckedOutDate($file.CheckedOutDate)
2492 | $obj | Add-Member NoteProperty CheckedOutByUser.LoginName($file.CheckedOutByUser.LoginName)
2493 | $obj | Add-Member NoteProperty CheckinComment($file.CheckinComment)
2494 | $obj | Add-Member NoteProperty ContentTag($file.ContentTag)
2495 | $obj | Add-Member NoteProperty ETag($file.ETag)
2496 | $obj | Add-Member NoteProperty Exists($file.Exists)
2497 | $obj | Add-Member NoteProperty Length($file.Length)
2498 | $obj | Add-Member NoteProperty LockedByUser.LoginName($file.LockedByUser.LoginName)
2499 | $obj | Add-Member NoteProperty MajorVersion($file.MajorVersion)
2500 | $obj | Add-Member NoteProperty MinorVersion($file.MinorVersion)
2501 | $obj | Add-Member NoteProperty ModifiedBy.LoginName($file.ModifiedBy.LoginName)
2502 | $obj | Add-Member NoteProperty ServerRelativeUrl($file.ServerRelativeUrl)
2503 | $obj | Add-Member NoteProperty Tag($file.Tag)
2504 | $obj | Add-Member NoteProperty TimeCreated($file.TimeCreated)
2505 | $obj | Add-Member NoteProperty TimeLastModified($file.TimeLastModified)
2506 | $obj | Add-Member NoteProperty Title($file.Title)
2507 | $obj | Add-Member NoteProperty UIVersion($file.UIVersion)
2508 | $obj | Add-Member NoteProperty UIVersionLabel($file.UIVersionLabel)
2509 | #>
2510 | Write-Output $file
2511 |
2512 |
2513 |
2514 | }
2515 |
2516 |
2517 |
2518 |
2519 |
2520 |
2521 |
2522 |
2523 | function Get-SPOFolderByServerRelativeUrl
2524 | {
2525 |
2526 | <#
2527 | .link
2528 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2529 |
2530 | #>
2531 |
2532 | param (
2533 | [Parameter(Mandatory=$true,Position=4)]
2534 | [string]$ServerRelativeUrl
2535 | )
2536 |
2537 |
2538 |
2539 | $folderCollection =
2540 | $ctx.Web.GetFolderByServerRelativeUrl($ServerRelativeUrl).Folders;
2541 | $ctx.Load($folderCollection)
2542 | $ctx.ExecuteQuery()
2543 |
2544 |
2545 |
2546 | foreach ($fof in $folderCollection)
2547 | {
2548 | $obj = New-Object PSObject
2549 | $ctx.Load($fof.ListItemAllFields)
2550 | $ctx.ExecuteQuery()
2551 | $obj | Add-Member NoteProperty Name($fof.Name)
2552 | $obj | Add-Member NoteProperty Itemcount($fof.ItemCount)
2553 | $obj | Add-Member NoteProperty WelcomePage($fof.WelcomePage)
2554 |
2555 | Write-Output $obj
2556 | }
2557 | }
2558 |
2559 |
2560 |
2561 |
2562 | #
2563 | #
2564 | #
2565 | #
2566 | #
2567 | #
2568 | #
2569 | #
2570 | #
2571 | # Content Types
2572 | #
2573 | #
2574 | #
2575 | #
2576 | #
2577 | #
2578 | #
2579 | #
2580 | #
2581 | #
2582 | #
2583 | #
2584 |
2585 |
2586 |
2587 |
2588 |
2589 |
2590 |
2591 | function New-SPOListContentType
2592 | {
2593 |
2594 | <#
2595 | .link
2596 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2597 |
2598 | #>
2599 |
2600 | param(
2601 | [Parameter(Mandatory=$false,Position=4)]
2602 | [string]$Description,
2603 | [Parameter(Mandatory=$true,Position=5)]
2604 | [string]$Name,
2605 | [Parameter(Mandatory=$false,Position=6)]
2606 | [string]$Group,
2607 | [Parameter(ParameterSetName="setb", Mandatory=$true)]
2608 | [Parameter(ParameterSetName="seta", Mandatory=$true)]
2609 | [string]$ParentContentTypeID,
2610 | [Parameter(ParameterSetName="setc", Mandatory=$true)]
2611 | [Parameter(ParameterSetName="setd", Mandatory=$true)]
2612 | [string]$ContentTypeID="",
2613 | [Parameter(ParameterSetName="setc", Mandatory=$true)]
2614 | [Parameter(ParameterSetName="seta", Mandatory=$true)]
2615 | [string]$ListID,
2616 | [Parameter(ParameterSetName="setd", Mandatory=$true)]
2617 | [Parameter(ParameterSetName="setb", Mandatory=$true)]
2618 | [string]$ListName=""
2619 |
2620 | )
2621 |
2622 |
2623 |
2624 | $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
2625 | if($PSBoundParameters.ContainsKey("Description"))
2626 | {$lci.Description=$Description}
2627 | if($PSBoundParameters.ContainsKey("Group"))
2628 | {$lci.Group=$Group}
2629 | $lci.Name=$Name
2630 | switch ($PsCmdlet.ParameterSetName)
2631 | {
2632 | "seta" { $lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID);
2633 | $ContentType = $ctx.Web.Lists.GetByID($ListID).ContentTypes.Add($lci); break}
2634 | "setb" { $lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID);
2635 | $ContentType = $ctx.Web.Lists.GetByTitle($ListName).ContentTypes.Add($lci); break}
2636 | "setc" { $lci.ID=$ContentTypeID;
2637 | $ContentType = $ctx.Web.Lists.GetByID($ListID).ContentTypes.Add($lci); break}
2638 | "setd" { $lci.ID=$ContentTypeID;
2639 | $ContentType = $ctx.Web.Lists.GetByTitle($ListName).ContentTypes.Add($lci); break}
2640 | }
2641 |
2642 |
2643 | $ctx.Load($contentType)
2644 | try
2645 | {
2646 |
2647 | $ctx.ExecuteQuery()
2648 | Write-Host "Content Type " $Name " has been added to the list"
2649 | }
2650 | catch [Net.WebException]
2651 | {
2652 | Write-Host $_.Exception.ToString()
2653 | }
2654 | }
2655 |
2656 |
2657 |
2658 |
2659 | function New-SPOSiteContentType
2660 | {
2661 |
2662 | <#
2663 | .link
2664 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2665 |
2666 | #>
2667 |
2668 | param(
2669 | [Parameter(Mandatory=$false,Position=4)]
2670 | [string]$Description,
2671 | [Parameter(Mandatory=$true,Position=5)]
2672 | [string]$Name,
2673 | [Parameter(Mandatory=$false,Position=6)]
2674 | [string]$Group,
2675 | [Parameter(ParameterSetName="seta", Mandatory=$true,Position=7)]
2676 | [string]$ParentContentTypeID,
2677 | [Parameter(ParameterSetName="setb", Mandatory=$true,Position=8)]
2678 | [string]$ContentTypeID=""
2679 | )
2680 |
2681 |
2682 | $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
2683 | $lci.Name=$Name
2684 | if($PSBoundParameters.ContainsKey("Description"))
2685 | {$lci.Description=$Description}
2686 | if($PSBoundParameters.ContainsKey("Group"))
2687 | {$lci.Group=$Group}
2688 | switch ($PsCmdlet.ParameterSetName)
2689 | {
2690 | "seta" {$lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID); break}
2691 | "setb" {$lci.ID=$ContentTypeID; break}
2692 | }
2693 | $ContentType = $ctx.Web.ContentTypes.Add($lci)
2694 | $ctx.Load($contentType)
2695 | try
2696 | {
2697 |
2698 | $ctx.ExecuteQuery()
2699 | Write-Host "Content Type " $Name " has been added to the site"
2700 | }
2701 | catch [Net.WebException]
2702 | {
2703 | Write-Host $_.Exception.ToString()
2704 | }
2705 |
2706 |
2707 |
2708 | }
2709 |
2710 |
2711 |
2712 |
2713 |
2714 |
2715 |
2716 | function New-SPOListContentTypeColumn
2717 | {
2718 | <#
2719 | .link
2720 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2721 |
2722 | #>
2723 | param (
2724 |
2725 | [Parameter(Mandatory=$true,Position=0)]
2726 | [string]$ListTitle,
2727 | [Parameter(Mandatory=$true,Position=1)]
2728 | [string]$ColumnName,
2729 | [Parameter(Mandatory=$true,Position=2)]
2730 | [string]$ContentTypeID,
2731 | [Parameter(Mandatory=$false,Position=5)]
2732 | [switch]$ListColumn
2733 | )
2734 |
2735 |
2736 | $ctx.Load($ctx.Web.Lists)
2737 | $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
2738 | $ctx.Load($ll)
2739 | $ctx.Load($ll.ContentTypes)
2740 | $ctType=$ll.ContentTypes.GetByID($ContentTypeID)
2741 | $ctx.Load($ctType)
2742 | $ctx.ExecuteQuery()
2743 | if($ListColumn)
2744 | {
2745 | $field=$ll.Fields.GetByInternalNameOrTitle($ColumnName)
2746 | }
2747 | else{ $field=$ctx.Web.Fields.GetByInternalNameOrTitle($ColumnName) }
2748 |
2749 |
2750 | $link=new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation
2751 | $link.Field=$field
2752 | $fielsie=$ctType.FieldLinks.Add($link)
2753 | $ctType.Update($false)
2754 | $ctx.ExecuteQuery()
2755 |
2756 |
2757 |
2758 |
2759 | }
2760 |
2761 |
2762 |
2763 |
2764 |
2765 |
2766 | function New-SPOSiteContentTypeColumn
2767 | {
2768 | <#
2769 | .link
2770 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2771 |
2772 | #>
2773 | param (
2774 |
2775 | [Parameter(Mandatory=$true,Position=0)]
2776 | [string]$ContentTypeID,
2777 | [Parameter(Mandatory=$true,Position=1)]
2778 | [string]$ColumnName,
2779 | [Parameter(Mandatory=$true,Position=3)]
2780 | [bool]$UpdateChildren
2781 | )
2782 |
2783 |
2784 | $ctType=$ctx.Web.ContentTypes.GetByID($ContentTypeID)
2785 | $ctx.Load($ctType)
2786 | $ctx.ExecuteQuery()
2787 | $field=$ctx.Web.Fields.GetByInternalNameOrTitle($ColumnName)
2788 |
2789 | $link=new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation
2790 | $link.Field=$field
2791 | $fielsie=$ctType.FieldLinks.Add($link)
2792 | $ctType.Update($UpdateChildren)
2793 | $ctx.ExecuteQuery()
2794 |
2795 |
2796 |
2797 |
2798 | }
2799 |
2800 |
2801 |
2802 |
2803 | function Get-SPOContentType
2804 | {
2805 | <#
2806 | .link
2807 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2808 |
2809 | #>
2810 | param (
2811 |
2812 | [Parameter(Mandatory=$false,Position=0)]
2813 | [string]$ListTitle,
2814 | [Parameter(Mandatory=$false,Position=1)]
2815 | [switch]$Available
2816 | )
2817 |
2818 |
2819 | if($PSBoundParameters.ContainsKey("ListTitle"))
2820 | {
2821 | $ctTypes=$ctx.Web.Lists.GetByTitle($ListTitle).ContentTypes
2822 | $ctx.Load($ctTypes)
2823 | $ctx.ExecuteQuery()
2824 | }
2825 | elseif($Available)
2826 | {
2827 | $ctTypes=$ctx.Web.AvailableContentTypes
2828 | $ctx.Load($ctTypes)
2829 | $ctx.ExecuteQuery()
2830 |
2831 | }
2832 | else
2833 | {
2834 | $ctTypes=$ctx.Web.ContentTypes
2835 | $ctx.Load($ctTypes)
2836 | $ctx.ExecuteQuery()
2837 | }
2838 |
2839 |
2840 |
2841 | foreach($cc in $ctTypes)
2842 | {
2843 |
2844 | $ctx.Load($cc)
2845 | $ctx.Load($cc.FieldLinks)
2846 | $ctx.Load($cc.Fields)
2847 | $ctx.Load($cc.WorkflowAssociations)
2848 | $ctx.ExecuteQuery()
2849 | foreach($field in $cc.Fields)
2850 | {
2851 | $PropertyName="Field "+$field.ID
2852 | $cc | Add-Member NoteProperty $PropertyName($field.Title)
2853 | }
2854 | foreach($fieldlink in $cc.FieldLinks)
2855 | {
2856 | $PropertyName="Fieldlink "+$fieldlink.ID
2857 | $cc | Add-Member NoteProperty $PropertyName($fieldlink.Name)
2858 | }
2859 | foreach($workflow in $cc.WorkflowAssociations)
2860 | {
2861 | $PropertyName="Workflow "+$workflow.ID
2862 | $cc | Add-Member NoteProperty $PropertyName($workflow.Name)
2863 | }
2864 |
2865 | Write-Output $cc
2866 |
2867 | }
2868 |
2869 |
2870 |
2871 |
2872 |
2873 |
2874 | }
2875 |
2876 |
2877 | function Remove-SPOContentType
2878 | {
2879 | <#
2880 | .link
2881 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2882 |
2883 | #>
2884 | param (
2885 |
2886 | [Parameter(Mandatory=$false,Position=0)]
2887 | [string]$ListTitle,
2888 | [Parameter(Mandatory=$true,Position=1)]
2889 | [string]$ContentTypeID
2890 | )
2891 |
2892 |
2893 | if($PSBoundParameters.ContainsKey("ListTitle"))
2894 | {
2895 | $ctType=$ctx.Web.Lists.GetByTitle($ListTitle).ContentTypes.GetByID($ContentTypeID)
2896 | $ctx.Load($ctType)
2897 | $ctx.ExecuteQuery()
2898 | $ctType.DeleteObject()
2899 | $ctx.ExecuteQuery()
2900 | }
2901 | else
2902 | {
2903 | $ctType=$ctx.Web.ContentTypes.GetByID($ContentTypeID)
2904 | $ctx.Load($ctType)
2905 | $ctx.ExecuteQuery()
2906 | $ctType.DeleteObject()
2907 | $ctx.ExecuteQuery()
2908 |
2909 | }
2910 |
2911 |
2912 | }
2913 |
2914 |
2915 |
2916 | function Set-SPOContentType
2917 | {
2918 | <#
2919 | .link
2920 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
2921 |
2922 | #>
2923 | param (
2924 |
2925 | [Parameter(Mandatory=$false,Position=0)]
2926 | [string]$ListTitle,
2927 | [Parameter(Mandatory=$true,Position=1)]
2928 | [string]$ContentTypeID,
2929 | [Parameter(Mandatory=$false)]
2930 | [string]$Group,
2931 | [Parameter(Mandatory=$false)]
2932 | [string]$DisplayFormUrl,
2933 | [Parameter(Mandatory=$false)]
2934 | [string]$EditFormUrl,
2935 | [Parameter(Mandatory=$false)]
2936 | [bool]$Hidden,
2937 | [Parameter(Mandatory=$false)]
2938 | [string]$JSLink,
2939 | [Parameter(Mandatory=$false)]
2940 | [string]$NewFormUrl,
2941 | [Parameter(Mandatory=$false)]
2942 | [bool]$ReadOnly,
2943 | [Parameter(Mandatory=$false)]
2944 | [bool]$Sealed=$false,
2945 | [Parameter(Mandatory=$true)]
2946 | [bool]$UpdateChildren
2947 |
2948 | )
2949 |
2950 |
2951 | if($PSBoundParameters.ContainsKey("ListTitle"))
2952 | {
2953 | $ctType=$ctx.Web.Lists.GetByTitle($ListTitle).ContentTypes.GetByID($ContentTypeID)
2954 | $ctx.Load($ctType)
2955 | $ctx.ExecuteQuery()
2956 | }
2957 | else
2958 | {
2959 | $ctType=$ctx.Web.ContentTypes.GetByID($ContentTypeID)
2960 | $ctx.Load($ctType)
2961 | $ctx.ExecuteQuery()
2962 | }
2963 |
2964 | if($PSBoundParameters.ContainsKey("Group"))
2965 | {$ctType.Group=$Group}
2966 | if($PSBoundParameters.ContainsKey("DisplayFormUrl"))
2967 | {$ctType.DisplayFormUrl=$DisplayFormUrl}
2968 | if($PSBoundParameters.ContainsKey("EditFormUrl"))
2969 | {$ctType.EditFormUrl=$EditFormUrl}
2970 | if($PSBoundParameters.ContainsKey("Hidden"))
2971 | {$ctType.Hidden=$Hidden}
2972 | if($PSBoundParameters.ContainsKey("JSLink"))
2973 | {$ctType.JSLink=$JSLink}
2974 | if($PSBoundParameters.ContainsKey("NewFormUrl"))
2975 | {$ctType.NewFormUrl=$NewFormUrl}
2976 | if($PSBoundParameters.ContainsKey("ReadOnly"))
2977 | {$ctType.ReadOnly=$ReadOnly}
2978 | if($PSBoundParameters.ContainsKey("Sealed"))
2979 | {$ctType.Sealed=$Sealed}
2980 |
2981 | $ctType.Update($UpdateChildren)
2982 | $ctx.ExecuteQuery()
2983 |
2984 | }
2985 |
2986 |
2987 |
2988 | #
2989 | #
2990 | #
2991 | #
2992 | #
2993 | #
2994 | #
2995 | #
2996 | #
2997 | # Taxonomy
2998 | #
2999 | #
3000 | #
3001 | #
3002 | #
3003 | #
3004 | #
3005 | #
3006 | #
3007 | #
3008 | #
3009 | #
3010 |
3011 |
3012 |
3013 | function New-SPOTerm
3014 | {
3015 | param (
3016 | #[Parameter(Mandatory=$true,Position=4)]
3017 | #[string]$TermSetGuid,
3018 | [Parameter(Mandatory=$true,Position=5)]
3019 | [string]$Term,
3020 | [Parameter(Mandatory=$true,Position=6)]
3021 | [string]$TermLanguage
3022 | )
3023 |
3024 |
3025 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3026 | $ctx.Load($session)
3027 | $ctx.ExecuteQuery()
3028 |
3029 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3030 | $ctx.Load($termstore)
3031 | $ctx.ExecuteQuery()
3032 |
3033 | Write-Host "Termstore" -ForegroundColor Green
3034 | Write-Host "Term1"
3035 | $set=$termstore.GetTermSet($TermSetGuid)
3036 | $ctx.Load($set)
3037 | $ctx.Load($set.GetAllTerms())
3038 | $ctx.ExecuteQuery()
3039 | $guid = [guid]::NewGuid()
3040 | Write-Host $guid
3041 | $term=$set.CreateTerm($Term, $TermLanguage,$guid)
3042 |
3043 | $termstore.CommitAll()
3044 |
3045 | $ctx.ExecuteQuery()
3046 |
3047 | }
3048 |
3049 |
3050 | function Get-SPOTermGroups
3051 | {
3052 |
3053 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3054 | $ctx.Load($session)
3055 | $ctx.ExecuteQuery()
3056 |
3057 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3058 | $ctx.Load($termstore)
3059 | $ctx.ExecuteQuery()
3060 |
3061 | $groups=$termstore.Groups
3062 | $ctx.Load($groups)
3063 |
3064 | $ctx.ExecuteQuery()
3065 |
3066 | foreach($group in $groups)
3067 | {
3068 | $ctx.Load($group)
3069 | $ctx.Load($group.TermSets)
3070 | $ctx.ExecuteQuery()
3071 | Write-Output $group
3072 | }
3073 |
3074 | }
3075 |
3076 |
3077 | function Get-SPOTermSets
3078 | {
3079 | param (
3080 | [Parameter(ParameterSetName="groupName",Mandatory=$true)]
3081 | [string]$TermGroupName="",
3082 | [Parameter(ParameterSetName="groupId", Mandatory=$false)]
3083 | [string]$TermGroupId=""
3084 | )
3085 |
3086 |
3087 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3088 | $ctx.Load($session)
3089 | $ctx.ExecuteQuery()
3090 |
3091 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3092 | $ctx.Load($termstore)
3093 | $ctx.ExecuteQuery()
3094 | if($TermGroupName -eq "" -and ($TermGroupId -eq ""))
3095 | {
3096 | $groups=$termstore.Groups
3097 | $ctx.Load($groups)
3098 | $ctx.ExecuteQuery()
3099 |
3100 | foreach($group in $groups)
3101 | {
3102 | $ctx.Load($group)
3103 | $ctx.Load($group.TermSets)
3104 | $ctx.ExecuteQuery()
3105 | foreach($termset in $group.TermSets)
3106 | {
3107 | $ctx.Load($termset)
3108 | $ctx.Load($termset.Terms)
3109 | $ctx.ExecuteQuery()
3110 | Write-Output $termset
3111 |
3112 | }
3113 |
3114 | }
3115 | }
3116 | else
3117 | {
3118 | $group;
3119 | if($TermGroupName -ne ""){
3120 | $group=$termstore.Groups.GetByName($TermGroupName)
3121 | }
3122 | elseif($TermGroupId -ne ""){
3123 | $group=$termstore.Groups.GetById($TermGroupId)
3124 | }
3125 | else{
3126 | $group=$termstore.Groups[0]
3127 | }
3128 | $ctx.Load($group)
3129 | $ctx.Load($group.TermSets)
3130 | $ctx.ExecuteQuery()
3131 | foreach($termset in $group.TermSets)
3132 | {
3133 | $ctx.Load($termset)
3134 | $ctx.Load($termset.Terms)
3135 | $ctx.ExecuteQuery()
3136 | Write-Output $termset
3137 |
3138 | }
3139 |
3140 | }
3141 |
3142 |
3143 | }
3144 |
3145 |
3146 | function Get-SPOTermStore
3147 | {
3148 |
3149 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3150 | $ctx.Load($session)
3151 | $ctx.ExecuteQuery()
3152 |
3153 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3154 | $ctx.Load($termstore)
3155 | $ctx.Load($termstore.Groups)
3156 | $ctx.ExecuteQuery()
3157 |
3158 | Write-Output $termstore
3159 |
3160 | }
3161 |
3162 | function Get-SPOHashTagsTermSet
3163 | {
3164 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3165 | $ctx.Load($session)
3166 | $ctx.ExecuteQuery()
3167 |
3168 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3169 | $ctx.Load($termstore)
3170 | $ctx.Load($termstore.HashTagsTermSet)
3171 | $ctx.Load($termstore.HashTagsTermSet.Terms)
3172 | $ctx.ExecuteQuery()
3173 | Write-Output $termstore.HashTagsTermSet
3174 | }
3175 |
3176 | function Get-SPOHashTagsTerms
3177 | {
3178 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3179 | $ctx.Load($session)
3180 | $ctx.ExecuteQuery()
3181 |
3182 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3183 | $hashtagtermset=$termstore.HashTagsTermSet
3184 | $ctx.Load($termstore)
3185 | $ctx.Load($hashtagtermset)
3186 | $ctx.Load($hashtagtermset.Terms)
3187 | $ctx.ExecuteQuery()
3188 | foreach($term in $hashtagtermset.Terms)
3189 | {
3190 | $ctx.Load($term)
3191 | $ctx.Load($term.Terms)
3192 | $ctx.Load($term.TermSets)
3193 | $ctx.Load($term.Labels)
3194 | $ctx.Load($term.ReusedTerms)
3195 | $ctx.ExecuteQuery()
3196 | Write-Output $term
3197 | }
3198 | }
3199 |
3200 | function Get-SPOKeyWordsTermSet
3201 | {
3202 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3203 | $ctx.Load($session)
3204 | $ctx.ExecuteQuery()
3205 |
3206 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3207 | $keywordsTermStore=$termstore.KeywordsTermSet
3208 | $ctx.Load($termstore)
3209 | $ctx.Load($keywordsTermStore)
3210 | $ctx.Load($keywordsTermStore.Terms)
3211 | $ctx.ExecuteQuery()
3212 | Write-Output $keywordsTermStore
3213 | }
3214 |
3215 |
3216 |
3217 | function New-SPOTermGroup
3218 | {
3219 | param(
3220 | [Parameter(Mandatory=$true)]
3221 | [string]$Name,
3222 | [Parameter(Mandatory=$false)]
3223 | [string]$GUID=""
3224 | )
3225 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3226 | $ctx.Load($session)
3227 | $ctx.ExecuteQuery()
3228 |
3229 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3230 | if($GUID -eq ""){$GUID = [guid]::NewGuid()}
3231 | $group=$termstore.CreateGroup($Name,$GUID)
3232 | try
3233 | {
3234 | $ctx.ExecuteQuery()
3235 | Write-Host "Group " $Name " created successfully."
3236 |
3237 | }
3238 | catch [Net.WebException]
3239 | {
3240 |
3241 | Write-Host "Couldn't create a group "$Name $_.Exception.ToString() -ForegroundColor Red
3242 | }
3243 |
3244 | }
3245 |
3246 | function Set-SPOTermGroup
3247 | {
3248 | param(
3249 | [Parameter(ParameterSetName="ByGUID",Mandatory=$true)]
3250 | [string]$GUID="",
3251 | [Parameter(ParameterSetName="FromPipeline", ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
3252 | $group=$null,
3253 | [Parameter(Mandatory=$false)]
3254 | [string]$Description
3255 | )
3256 | BEGIN{
3257 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3258 | $ctx.Load($session)
3259 | $ctx.ExecuteQuery()
3260 |
3261 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3262 | }
3263 | PROCESS{
3264 | if($group -eq $null)
3265 | {
3266 | $group=$termstore.GetGroup($GUID)
3267 | $ctx.Load($termstore)
3268 | $ctx.Load($group)
3269 | $ctx.ExecuteQuery()
3270 | }
3271 | $group.Description=$Description
3272 | $ctx.ExecuteQuery()
3273 | }
3274 | }
3275 |
3276 | function New-SPOTermSet
3277 | {
3278 | param(
3279 | [Parameter(ParameterSetName="ByName",Mandatory=$true)]
3280 | [string]$TermGroupName="",
3281 | [Parameter(ParameterSetName="ByID",Mandatory=$true)]
3282 | [string]$TermGroupID="",
3283 | [Parameter(ParameterSetName="ByGroup",Mandatory=$true,ValueFromPipeline=$true)]
3284 | $TermGroup="",
3285 | [Parameter(Mandatory=$true)]
3286 | [string]$TermSetName,
3287 | [Parameter(Mandatory=$false)]
3288 | [int]$LanguageID=1033,
3289 | [Parameter(Mandatory=$false)]
3290 | $GUID=""
3291 | )
3292 |
3293 | BEGIN{
3294 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3295 | $ctx.Load($session)
3296 | $ctx.ExecuteQuery()
3297 | }
3298 | PROCESS{
3299 | $termstore = $session.GetDefaultSiteCollectionTermStore()
3300 | if($TermGroupName -ne "")
3301 | { $group=$termstore.Groups.GetByName($TermGroupName)}
3302 | elseif($TermGroupID -ne "")
3303 | { $group=$termstore.Groups.GetById($TermGroupID)}
3304 | elseif($group -ne "")
3305 | {
3306 | $group=$TermGroup
3307 | }
3308 | else
3309 | {
3310 | Write-Host "Could not retrieve the group. Missing parameters"
3311 | }
3312 |
3313 | $ctx.Load($group)
3314 | $ctx.Load($group.TermSets)
3315 | $ctx.ExecuteQuery()
3316 |
3317 | if($GUID -eq "")
3318 | {
3319 | $GUID = [guid]::NewGuid()
3320 | }
3321 |
3322 | $termSet=$group.CreateTermSet($TermSetName, $GUID, $LanguageID)
3323 | $ctx.ExecuteQuery()
3324 | return $termset
3325 | }
3326 |
3327 |
3328 | }
3329 |
3330 | function Set-SPOTermSet
3331 | {
3332 | param(
3333 | [Parameter(Mandatory=$true, Position=1)]
3334 | [Microsoft.SharePoint.Client.Taxonomy.TermSet]$TermSet,
3335 | [Parameter(Mandatory=$false)]
3336 | [string]$Description="",
3337 | [Parameter(Mandatory=$false)]
3338 | [bool]$IsOpenForTermCreation,
3339 | [Parameter(Mandatory=$false)]
3340 | [bool]$IsAvailableForTagging,
3341 | [Parameter(Mandatory=$false)]
3342 | [string]$Name,
3343 | [Parameter(Mandatory=$false)]
3344 | [string]$Owner,
3345 | [Parameter(Mandatory=$false)]
3346 | [string]$StakeholderToAdd,
3347 | [Parameter(Mandatory=$false)]
3348 | [string]$StakeholderToRemove
3349 | )
3350 | if($Description -ne "")
3351 | {
3352 | $TermSet.Description=$Description
3353 | }
3354 | if($PSBoundParameters.ContainsKey("IsOpenForTermCreation"))
3355 | {
3356 | $TermSet.IsOpenForTermCreation=$IsOpenForTermCreation
3357 | }
3358 | if($PSBoundParameters.ContainsKey("IsOpenForTermCreation"))
3359 | {
3360 | $TermSet.IsAvailableForTagging=$IsAvailableForTagging
3361 | }
3362 | if($PSBoundParameters.ContainsKey("Name"))
3363 | {
3364 | $TermSet.Name=$Name
3365 | }
3366 | if($PSBoundParameters.ContainsKey("Owner"))
3367 | {
3368 | $TermSet.Owner=$Owner
3369 | }
3370 | if($PSBoundParameters.ContainsKey("StakeholderToAdd"))
3371 | {
3372 | $TermSet.AddStakeholder($StakeholderToAdd)
3373 | }
3374 | if($PSBoundParameters.ContainsKey("StakeholderToRemove"))
3375 | {
3376 | $TermSet.DeleteStakeholder($StakeholderToRemove)
3377 | }
3378 |
3379 | try
3380 | {
3381 | $ctx.ExecuteQuery()
3382 | }
3383 | catch [Net.WebException]
3384 | {
3385 | Write-Host "Could not update the termset. " $_.Exception.ToString() -ForegroundColor Red
3386 | }
3387 |
3388 | }
3389 |
3390 | function Get-SPOTerm
3391 | {
3392 | param(
3393 | [Parameter(Mandatory=$true, Position=1)]
3394 | [GUID]$Guid
3395 | )
3396 | $session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
3397 | $ctx.Load($session)
3398 | $ctx.ExecuteQuery()
3399 | $termstore = $session.GetDefaultSiteCollectionTermStore();
3400 | $term=$termstore.GetTerm($Guid)
3401 | $ctx.Load($termstore)
3402 | $ctx.Load($term)
3403 | $ctx.Load($term.Terms)
3404 | $ctx.Load($term.TermSets)
3405 | $ctx.ExecuteQuery()
3406 | Write-Output $term
3407 |
3408 | }
3409 |
3410 |
3411 |
3412 | #
3413 | #
3414 | #
3415 | #
3416 | #
3417 | #
3418 | #
3419 | #
3420 | #
3421 | # Web
3422 | #
3423 | #
3424 | #
3425 | #
3426 | #
3427 | #
3428 | #
3429 | #
3430 | #
3431 | #
3432 | #
3433 | #
3434 |
3435 | function Get-SPOWeb
3436 | {
3437 |
3438 | <#
3439 | .link
3440 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
3441 |
3442 | #>
3443 | param (
3444 | [Parameter(Mandatory=$false,Position=4)]
3445 | [bool]$IncludeSubsites=$false
3446 | )
3447 |
3448 |
3449 | $ctx.Load($ctx.Web)
3450 | $ctx.Load($ctx.Web.Webs)
3451 | $ctx.ExecuteQuery()
3452 |
3453 |
3454 |
3455 |
3456 | # Get the root
3457 | $obj = new-Object PSOBject
3458 | $obj | Add-Member NoteProperty AllowRSSFeeds($ctx.Web.Webs[$i].AllowRssFeeds)
3459 | $obj | Add-Member NoteProperty Created($ctx.Web.Webs[$i].Created)
3460 | $obj | Add-Member NoteProperty CustomMasterUrl($ctx.Web.Webs[$i].CustomMasterUrl)
3461 | $obj | Add-Member NoteProperty Description($ctx.Web.Webs[$i].Description)
3462 | $obj | Add-Member NoteProperty EnableMinimalDownload($ctx.Web.Webs[$i].EnableMinimalDownload)
3463 | $obj | Add-Member NoteProperty ID($ctx.Web.Webs[$i].Id)
3464 | $obj | Add-Member NoteProperty Language($ctx.Web.Webs[$i].Language)
3465 | $obj | Add-Member NoteProperty LastItemModifiedDate($ctx.Web.Webs[$i].LastItemModifiedDate)
3466 | $obj | Add-Member NoteProperty MasterUrl($ctx.Web.Webs[$i].MasterUrl)
3467 | $obj | Add-Member NoteProperty QuickLaunchEnabled($ctx.Web.Webs[$i].QuickLaunchEnabled)
3468 | $obj | Add-Member NoteProperty RecycleBinEnabled($ctx.Web.Webs[$i].RecycleBinEnabled)
3469 | $obj | Add-Member NoteProperty ServerRelativeUrl($ctx.Web.Webs[$i].ServerRelativeUrl)
3470 | $obj | Add-Member NoteProperty Title($ctx.Web.Webs[$i].Title)
3471 | $obj | Add-Member NoteProperty TreeViewEnabled($ctx.Web.Webs[$i].TreeViewEnabled)
3472 | $obj | Add-Member NoteProperty UIVersion($ctx.Web.Webs[$i].UIVersion)
3473 | $obj | Add-Member NoteProperty UIVersionConfigurationEnabled($ctx.Web.Webs[$i].UIVersionConfigurationEnabled)
3474 | $obj | Add-Member NoteProperty Url($ctx.Web.Webs[$i].Url)
3475 | $obj | Add-Member NoteProperty WebTemplate($ctx.Web.Webs[$i].WebTemplate)
3476 |
3477 | Write-Output $obj
3478 |
3479 | # Get the subsites
3480 | if($IncludeSubsites){
3481 | if($ctx.Web.Webs.Count -eq 0)
3482 | {
3483 | Write-Host "No subsites found"
3484 |
3485 | }
3486 | for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++)
3487 | {
3488 | $obj = new-Object PSOBject
3489 | $obj | Add-Member NoteProperty AllowRSSFeeds($ctx.Web.Webs[$i].AllowRssFeeds)
3490 | $obj | Add-Member NoteProperty Created($ctx.Web.Webs[$i].Created)
3491 | $obj | Add-Member NoteProperty CustomMasterUrl($ctx.Web.Webs[$i].CustomMasterUrl)
3492 | $obj | Add-Member NoteProperty Description($ctx.Web.Webs[$i].Description)
3493 | $obj | Add-Member NoteProperty EnableMinimalDownload($ctx.Web.Webs[$i].EnableMinimalDownload)
3494 | $obj | Add-Member NoteProperty ID($ctx.Web.Webs[$i].Id)
3495 | $obj | Add-Member NoteProperty Language($ctx.Web.Webs[$i].Language)
3496 | $obj | Add-Member NoteProperty LastItemModifiedDate($ctx.Web.Webs[$i].LastItemModifiedDate)
3497 | $obj | Add-Member NoteProperty MasterUrl($ctx.Web.Webs[$i].MasterUrl)
3498 | $obj | Add-Member NoteProperty QuickLaunchEnabled($ctx.Web.Webs[$i].QuickLaunchEnabled)
3499 | $obj | Add-Member NoteProperty RecycleBinEnabled($ctx.Web.Webs[$i].RecycleBinEnabled)
3500 | $obj | Add-Member NoteProperty ServerRelativeUrl($ctx.Web.Webs[$i].ServerRelativeUrl)
3501 | $obj | Add-Member NoteProperty Title($ctx.Web.Webs[$i].Title)
3502 | $obj | Add-Member NoteProperty TreeViewEnabled($ctx.Web.Webs[$i].TreeViewEnabled)
3503 | $obj | Add-Member NoteProperty UIVersion($ctx.Web.Webs[$i].UIVersion)
3504 | $obj | Add-Member NoteProperty UIVersionConfigurationEnabled($ctx.Web.Webs[$i].UIVersionConfigurationEnabled)
3505 | $obj | Add-Member NoteProperty Url($ctx.Web.Webs[$i].Url)
3506 | $obj | Add-Member NoteProperty WebTemplate($ctx.Web.Webs[$i].WebTemplate)
3507 |
3508 | Write-Output $obj
3509 | }
3510 |
3511 | }
3512 |
3513 |
3514 |
3515 | }
3516 |
3517 |
3518 |
3519 |
3520 |
3521 |
3522 |
3523 |
3524 |
3525 |
3526 |
3527 | #
3528 | #
3529 | #
3530 | #
3531 | #
3532 | #
3533 | #
3534 | #
3535 | #
3536 | # Connect
3537 | #
3538 | #
3539 | #
3540 | #
3541 | #
3542 | #
3543 | #
3544 | #
3545 | #
3546 | #
3547 | #
3548 | #
3549 |
3550 |
3551 | function Connect-SPOCSOM
3552 | {
3553 |
3554 | <#
3555 | .link
3556 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
3557 |
3558 | #>
3559 |
3560 | [CmdletBinding(DefaultParameterSetName="Credential")]
3561 | param (
3562 | [Parameter(Mandatory = $True, Position=1, ParameterSetName = "Credential")]
3563 | $Credential,
3564 | [Parameter(Mandatory = $True, Position=1, ParameterSetName = "Username")]
3565 | [string]$Username,
3566 | [Parameter(Mandatory = $True, Position=2)]
3567 | [string]$Url
3568 | )
3569 |
3570 | Switch ($PSCmdlet.ParameterSetName) {
3571 | "Credential" {
3572 | $Username = $Credential.Username
3573 | $Password = $Credential.Password
3574 | }
3575 | "Username" {
3576 | $password = Read-Host "Password" -AsSecureString
3577 | }
3578 | }
3579 |
3580 |
3581 | $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
3582 | $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
3583 | $ctx.ExecuteQuery()
3584 | $global:ctx=$ctx
3585 | }
3586 |
3587 | function Connect-SPCSOM
3588 | {
3589 |
3590 | <#
3591 | .link
3592 | http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
3593 |
3594 | #>
3595 |
3596 | [CmdletBinding(DefaultParameterSetName="Credential")]
3597 | param (
3598 | [Parameter(Mandatory = $True, Position=1, ParameterSetName = "Credential")]
3599 | $Credential,
3600 | [Parameter(Mandatory = $True, Position=1, ParameterSetName = "Username")]
3601 | [string]$Username,
3602 | [Parameter(Mandatory = $True, Position=2)]
3603 | [string]$Url
3604 | )
3605 |
3606 | Switch ($PSCmdlet.ParameterSetName) {
3607 | "Credential" {
3608 | $Username = $Credential.Username
3609 | $Password = $Credential.Password
3610 | }
3611 | "Username" {
3612 | $password = Read-Host "Password" -AsSecureString
3613 | }
3614 | }
3615 |
3616 | $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
3617 | $ctx.Credentials = New-Object System.Net.NetworkCredential($Username, $password)
3618 | $ctx.ExecuteQuery()
3619 | $global:ctx=$ctx
3620 | }
3621 |
3622 |
3623 | $global:ctx
3624 |
3625 |
3626 |
3627 |
3628 |
3629 |
3630 | # Paths to SDK. Please verify location on your computer.
3631 | Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
3632 | Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
3633 | Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
3634 |
3635 |
3636 |
3637 | Export-ModuleMember -Function "Connect-SPCSOM","New-SPOTerm", "Get-SPOTermGroups", "Get-SPOTermSets", "Get-SPOTermStore", "Get-SPOHashTagsTermSet", "Get-SPOHashTagsTerms", "Get-SPOKeyWordsTermSet", "New-SPOTermGroup", "Set-SPOTermGroup", "New-SPOTermSet", "Get-SPOTerm", "Set-SPOTermSet", "New-SPOListContentType","Get-SPOListItemVersions","Connect-SPOCSOM","New-SPOSiteContentType","New-SPOSiteContentTypeColumn","New-SPOListContentTypeColumn", "Get-SPOContentType", "Remove-SPOContentType","Set-SPOContentType","New-SPOListView","Set-SPOListView","Remove-SPOListView","Get-SPOListView","Get-SPOWeb","Get-SPOListCount","Get-SPOList", "Set-SPOList", "New-SPOList","Set-SPOListCheckout","Set-SPOListVersioning","Set-SPOListMinorVersioning","Remove-SPOListInheritance","Restore-SPOListInheritance","Set-SPOListContentTypesEnabled","Remove-SPOList","Set-SPOListFolderCreationEnabled","Set-SPOListIRMEnabled","Get-SPOListColumn","New-SPOListColumn","Set-SPOListColumn","Remove-SPOListColumn","Get-SPOListColumnFieldIsObjectPropertyInstantiated","Get-SPOListColumnFieldIsPropertyAvailable","New-SPOListChoiceColumn","Get-SPOListFields","Get-SPOListItems","New-SPOListItem","Remove-SPOListItemInheritance","Remove-SPOListItemPermissions","Restore-SPOListItemInheritance","Remove-SPOListItem","Set-SPOListItem","Set-SPOFileCheckout","Approve-SPOFile","Set-SPOFileCheckin","Copy-SPOFile","Remove-SPOFile","Deny-SPOFileApproval","Get-SPOFileIsPropertyAvailable","Move-SPOFile","Publish-SPOFile","Undo-SPOFileCheckout","Undo-SPOFilePublish","Get-SPOFolderFilesCount","Get-SPOFolderFiles","Get-SPOFileByServerRelativeUrl","Get-SPOFolderByServerRelativeUrl","Connect-SPOCSOM"
3638 |
--------------------------------------------------------------------------------