Forum Discussion
PowerShell examples - Get-SPOList and Get-SPOListItems
Pieter Veenstra wrote:
The one line option :smileyhappy: :
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues
Thanks - I like it but I have discoved the same issue as I have my code snippet
I need those names for auditing purposes
Id Name Modified Author -- ---- -------- ------ 24 24_.000 17/11/2016 14:44:39 Microsoft.SharePoint.Client.FieldUserValue 25 25_.000 17/11/2016 15:01:47 Microsoft.SharePoint.Client.FieldUserValue 27 27_.000 17/11/2016 14:47:39 Microsoft.SharePoint.Client.FieldUserValue
to get the Author details you could do this:
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author.Email
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author.LookupValue
- Daniel WesterdaleJun 09, 2017Iron Contributor
Thanks , all I needed was to pipe the Select statement and then field nivarna . Thanks again
Daniel
- Jun 09, 2017
How about using a select
so for example you could run
dir | select Name, Length
to display files in a folder, but just display their name and length.
Similar your example:
(Get-PnPListItem -web (Get-PnPWeb) -List ((Get-PnPList -web (Get-PnPWeb))|where {$_.Title -eq $listNewJoiners})).FieldValues | select First_x0020_Name, Last_x0020_Name - Daniel WesterdaleJun 09, 2017Iron Contributor
Good morning. I have previously written PS to get file data on every library and every site without issues. Today, I am asked to report on the output from a Nintex form and Workflow I created last year:
The ps below works ( even though I hate the syntax) . However, I now want to bring back multiple fields such as FieldValues.Last_x0020_Name etc, I awas hoping to do this with a single line - this is what I am struggling with:
(Get-PnPListItem -web (Get-PnPWeb) -List ((Get-PnPList -web (Get-PnPWeb))|where {$_.Title -eq $listNewJoiners})).FieldValues.First_x0020_Name - Daniel WesterdaleMay 15, 2017Iron Contributor
Kwok-Ho Lam wrote:Only 2 calls to the server in this case, instead of 12 and saves 3 Where-clauses on the clientside, since the server is much faster. You can also add CAML to filter through items
$query = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>123</Value></Eq></Where></Query></View>"
$SalesListItems = Get-SPOListItem -List "Sales list" -Query $query
On the subject of using a query , Get-PnPListItem seems limited, if we want to bring the non default fieds. Say I view all FIles in libraries and or Folders in one or more Team Sites that were modified in the last month
$startDate = Get-Date "01/04/2017" $startDatestring = $startDate.ToString("yyyy-MM-ddTHH:mm:ssZ") $endDate = Get-Date "01/05/2017" $endDatestring = $endDate.ToString("yyyy-MM-ddTHH:mm:ssZ") $query = ` "<View><Query><Where> ` <And> ` <Geq> ` <FieldRef Name='Modifed' /> <Value IncludeTimeValue='FALSE' ` Type='DateTime'>" + $startDatestring + "</Value> ` </Geq> ` <Leq> ` <FieldRef Name='Modifed' /> ` <Value IncludeTimeValue='FALSE' Type='DateTime'>" + $endDatestring + "</Value> ` </Leq> ` </And> ` </Where></Query></View>" # THIS WON'T WORK AS YOU NEED -Fields "FileLeafRef", "Modified" IF YOU WANT TO GET THIS INCLUDED
# IN THE OUTPUT BUT THS MEANS -QUERY IS IGNORED Get-PnPListItem -List Document -Query $query -Web $locationWebIf the above is not possible then it is back to bringing everything back....
Foreach($item in $items) { write-host $item.Modified.ToString() // check Modified date range here }Just seems not the quickest way to get the results I am looking for ;-( . Is the query with extended attributes something I should request?
- Kwok-Ho LamJan 16, 2017Copper Contributor
Pieter Veenstra wrote:to get the Author details you could do this:
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author.Email
(Get-SPOListItem -web (Get-SPOWeb) -List ((Get-SPOList -web (Get-SPOWeb))|where {$_.Title -eq "Sales list"}))[1].FieldValues.Author.LookupValue
Everytime you use Get-SPO.... it triggers a call to the server. for perfomance enhancements (and since the ListTitle is already hardcoded) use something like:
$url = "http://localhost"
Connect-SPOnline –Url $url -CurrentCredentials
(Get-SPOListItem -List "Sales list")[1].FieldValues.Author.LookupValue
It saves in this case 50% of the calls to the server. or better:
$url = "http://localhost"
Connect-SPOnline –Url $url -CurrentCredentials
$SalesListItems = Get-SPOListItem -List "Sales list"
$SalesListItems[1].FieldValues.Author
$SalesListItems[1].FieldValues.Author.Email
$SalesListItems[1].FieldValues.Author.LookupValue
Only 2 calls to the server in this case, instead of 12 and saves 3 Where-clauses on the clientside, since the server is much faster. You can also add CAML to filter through items
$query = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>123</Value></Eq></Where></Query></View>"
$SalesListItems = Get-SPOListItem -List "Sales list" -Query $query
- Daniel WesterdaleNov 17, 2016Iron ContributorThanks very much I use that.