Skip to content

Commit c4628eb

Browse files
Merge pull request #195 from PowershellScripts/readmeBranch
Readme branch
2 parents 13e081f + 1398124 commit c4628eb

File tree

1 file changed

+103
-1
lines changed
  • Getting SPO objects with REST/Script to get SharePoint objects with REST

1 file changed

+103
-1
lines changed
Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,103 @@
1-
.
1+
Short script to retrieve SharePoint Online objects, such as
2+
3+
lists
4+
content types
5+
fields/columns
6+
alerts
7+
event receivers
8+
features
9+
site groups
10+
users
11+
workflow associations
12+
13+
14+
15+
16+
How does it work?
17+
Open the file, enter your tenant's data:
18+
19+
20+
21+
```PowerShell
22+
23+
#Enter the data
24+
$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
25+
$username="t@t321.onmicrosoft.com"
26+
$Url="https://t321.sharepoint.com/standard"
27+
$object="lists"
28+
```
29+
30+
31+
$object refers to object you want to retrieve. Example objects are:
32+
33+
lists
34+
contenttypes
35+
availablefields
36+
alerts
37+
eventreceivers
38+
features
39+
sitegroups
40+
siteusers
41+
workflowassociations
42+
but you can also use anything that would work with the REST api in the browser, such as :
43+
44+
lists/getbytitle('biblioteka')
45+
"" (empty string to retrieve the web object properties)
46+
allproperties
47+
lists/getbytitle('biblioteka')/files
48+
49+
50+
You will be asked for password during execution. Do not enter your password in the file.
51+
52+
53+
54+
Then you can modify the last cmdlet:
55+
56+
57+
58+
```PowerShell
59+
Get-SPOObject -Username $username -Url $Url -password $AdminPassword -object $object
60+
```
61+
62+
63+
To retrieve whatever you need in a friendly and familiar Powershell fashion, e.g.:
64+
65+
66+
67+
```PowerShell
68+
Get-SPOObject -Username $username -Url $Url -password $AdminPassword -object "lists" | select title
69+
```
70+
```PowerShell
71+
Get-SPOObject -Username t@t321.onmicrosoft.com -password $password -url https://t321.sharepoint.
72+
com/standard -object "lists/getbytitle('biblioteka')/files" | where {$_.CreatedBy.Name -eq "Ana Trial"} | select Name, CreatedBy
73+
```
74+
75+
76+
77+
78+
The script can serve to pull all kinds of data from SharePoint Online in an admin-friendly Powershell way and can help deliver this data in a report form:
79+
80+
81+
82+
```PowerShell
83+
Get-SPOObject -Username t@t321.onmicrosoft.com -password $password -url https://t321.sharepoint.com/standard -object "lists/getbytitle('biblioteka')/files" | where {$_.CreatedBy.Name -eq "Ana Trial"} | export-csv c:\MyReport.csv
84+
```
85+
86+
87+
88+
89+
90+
91+
If you plan on using it more often, I recommend a module with a cmdlet that serves the same purpose. After importing the module, a cmdlet can be reused multiple times directly from Shell and is generally faster than executing script every time we need to pull data.
92+
93+
You can find the REST module in 3 versions:
94+
95+
- one with suggestions, limited but helpful when you are starting and don't know what your options are
96+
97+
- 2nd for users who have idea about REST and will be able to define their objects within web without any hints (most recommended)
98+
99+
- 3rd one free-style allowing you to pull anything under /_api/ so not only web but also site objects
100+
101+
102+
103+

0 commit comments

Comments
 (0)