1- function Get-SPOListFields
2- {
3-
4- <#
5- . link
6- http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
7-
8- #>
9-
10-
11- param (
12- [Parameter (Mandatory = $true , Position = 3 )]
13- [string ]$ListTitle ,
14- [Parameter (Mandatory = $false , Position = 4 )]
15- [bool ]$IncludeSubsites = $false
16- )
1+ function Get-SPOListFields {
2+ <#
3+ . link
4+ http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
5+ #>
6+
7+ param (
8+ [Parameter (Mandatory = $true , Position = 3 )]
9+ [string ]$ListTitle ,
10+ [Parameter (Mandatory = $false , Position = 4 )]
11+ [bool ]$IncludeSubsites = $false
12+ )
1713
1814 $ll = $ctx.Web.Lists.GetByTitle ($ListTitle )
1915 $ctx.Load ($ll )
@@ -23,51 +19,48 @@ function Get-SPOListFields
2319
2420 $fieldsArray = @ ()
2521 $fieldslist = @ ()
26- foreach ( $fiel in $ll .Fields )
27- {
28- # 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
22+
23+ foreach ( $fiel in $ll .Fields ) {
24+ # 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
2925
30- $array = @ ()
31- $array += " InternalName"
26+ $array = @ ()
27+ $array += " InternalName"
3228 $array += " StaticName"
33- $array += " Title"
29+ $array += " Title"
3430
35- $obj = New-Object PSObject
36- $obj | Add-Member NoteProperty $array [0 ]($fiel.InternalName )
37- $obj | Add-Member NoteProperty $array [1 ]($fiel.StaticName )
38- $obj | Add-Member NoteProperty $array [2 ]($fiel.Title )
31+ $obj = New-Object PSObject
32+ $obj | Add-Member NoteProperty $array [0 ]($fiel.InternalName )
33+ $obj | Add-Member NoteProperty $array [1 ]($fiel.StaticName )
34+ $obj | Add-Member NoteProperty $array [2 ]($fiel.Title )
3935
40- $fieldsArray += $obj
41- $fieldslist += $fiel.InternalName
42- Write-Output $obj
43- }
36+ $fieldsArray += $obj
37+ $fieldslist += $fiel.InternalName
38+ Write-Output $obj
39+ }
4440
45-
46- $ctx .Dispose ()
41+ $ctx .Dispose ()
42+
4743 return $fieldsArray
48-
4944}
5045
5146
52- function Get-SPOListItems
53- {
47+ function Get-SPOListItems {
5448 <#
5549. link
5650http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
57-
5851 #>
5952
60- param (
61- [Parameter (Mandatory = $true , Position = 1 )]
62- [string ]$ListTitle ,
63- [Parameter (Mandatory = $false , Position = 2 )]
64- [bool ]$IncludeAllProperties = $false ,
65- [switch ]$Recursive ,
66- [Parameter (Mandatory = $false , Position = 4 )]
67- $DestinationLibrary ,
68- [Parameter (Mandatory = $false , Position = 5 )]
69- [bool ]$Overwrite
70- )
53+ param (
54+ [Parameter (Mandatory = $true , Position = 1 )]
55+ [string ]$ListTitle ,
56+ [Parameter (Mandatory = $false , Position = 2 )]
57+ [bool ]$IncludeAllProperties = $false ,
58+ [switch ]$Recursive ,
59+ [Parameter (Mandatory = $false , Position = 4 )]
60+ $DestinationLibrary ,
61+ [Parameter (Mandatory = $false , Position = 5 )]
62+ [bool ]$Overwrite
63+ )
7164
7265
7366 $ll = $ctx.Web.Lists.GetByTitle ($ListTitle )
@@ -76,90 +69,75 @@ function Get-SPOListItems
7669 $ctx.ExecuteQuery ()
7770 $i = 0
7871
72+ $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
73+ # $spqQuery.ViewAttributes = "Scope='Recursive'"
74+ $spqQuery.ViewXml = " <Where><Eq><FieldRef Name='Attachments' /><Value Type='Boolean'>1</Value></Eq></Where>" ;
7975
80-
81- $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
82- # $spqQuery.ViewAttributes = "Scope='Recursive'"
83- $spqQuery.ViewXml = " <Where><Eq><FieldRef Name='Attachments' /><Value Type='Boolean'>1</Value></Eq></Where>" ;
84- if ($Recursive )
85- {
86- $spqQuery.ViewXml += " <View Scope='RecursiveAll' />" ;
87- }
88- $bobo = Get-SPOListFields - ListTitle $ListTitle
76+ if ($Recursive ){
77+ $spqQuery.ViewXml += " <View Scope='RecursiveAll' />" ;
78+ }
79+
80+ $bobo = Get-SPOListFields - ListTitle $ListTitle
8981
9082
9183 $itemki = $ll.GetItems ($spqQuery )
9284 $ctx.Load ($itemki )
9385 $ctx.ExecuteQuery ()
9486
95-
96-
9787 $objArray = @ ()
9888
99- for ($j = 0 ;$j -lt $itemki.Count ;$j ++ )
100- {
89+ for ($j = 0 ;$j -lt $itemki.Count ;$j ++ ){
10190
10291 $attache = $itemki [$j ].AttachmentFiles
10392 $ctx.Load ($attache )
10493 $ctx.ExecuteQuery ()
10594 Write-Host $itemki [$j ][" Title" ] - BackgroundColor DarkCyan
106- foreach ( $att in $attache )
107- {
95+
96+ foreach ( $att in $attache ) {
10897 # Write-Output $att
10998 $file =
110- $ctx.Web.GetFileByServerRelativeUrl ($att.ServerRelativeUrl );
111- $ctx.Load ($file )
112- $ctx.ExecuteQuery ()
99+ $ctx.Web.GetFileByServerRelativeUrl ($att.ServerRelativeUrl );
100+ $ctx.Load ($file )
101+ $ctx.ExecuteQuery ()
113102
114103 $NewName = $file.Name
115104
116-
117- if ($DestinationLibrary.EndsWith (" /" )){}
118- else {$DestinationLibrary = $DestinationLibrary + " /" }
119- Write-Host " Processing " $file.Name
120- $file.CopyTo ($DestinationLibrary + $NewName , $Overwrite )
121- try
122- {
123- $ctx.ExecuteQuery ()
105+ if ($DestinationLibrary.EndsWith (" /" )){}
106+ else {$DestinationLibrary = $DestinationLibrary + " /" }
124107
125- Write-Host $file.Name " has been copied to" $DestinationLibrary - ForegroundColor DarkGreen
126- }
127- catch [Net.WebException ]
128- {
129- Write-Host $_.Exception.ToString ()
130- }
108+ Write-Host " Processing " $file.Name
109+ $file.CopyTo ($DestinationLibrary + $NewName , $Overwrite )
110+
111+ try {
112+ $ctx.ExecuteQuery ()
113+ Write-Host $file.Name " has been copied to" $DestinationLibrary - ForegroundColor DarkGreen
114+ }
115+ catch [Net.WebException ]{
116+ Write-Host $_.Exception.ToString ()
117+ }
131118 }
132-
133-
134119 }
120+ }
135121
136122
137- }
138-
139-
140- function Connect-SPOCSOM
141- {
142-
143- <#
144- . link
145- http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
146-
123+ function Connect-SPOCSOM {
124+ <#
125+ . link
126+ http://social.technet.microsoft.com/wiki/contents/articles/32334.sharepoint-online-spomod-cmdlets-resources.aspx
147127 #>
148128
149- param (
150- [Parameter (Mandatory = $true , Position = 1 )]
151- [string ]$Username ,
152- [Parameter (Mandatory = $true , Position = 3 )]
153- [string ]$Url
154-
155-
156- )
157-
158- $password = Read-Host " Password" - AsSecureString
159- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url )
160- $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username , $password )
161- $ctx.ExecuteQuery ()
162- $global :ctx = $ctx
129+ param (
130+ [Parameter (Mandatory = $true , Position = 1 )]
131+ [string ]$Username ,
132+ [Parameter (Mandatory = $true , Position = 3 )]
133+ [string ]$Url
134+ )
135+
136+ $password = Read-Host " Password" - AsSecureString
137+ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url )
138+ $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username , $password )
139+ $ctx.ExecuteQuery ()
140+ $global :ctx = $ctx
163141}
164142
165143
0 commit comments