PowerShell для получения элементов календаря SharePoint - PullRequest
0 голосов
/ 29 мая 2020

Я ищу возможность получать элементы календаря SharePoint с помощью PowerShell. Не могли бы вы ответить, есть ли у вас лучший способ достижения?

Я хочу загрузить все элементы календаря в формате csv с windows 10 машин.

Заранее спасибо.

Ответы [ 2 ]

0 голосов
/ 01 июня 2020

Вы можете получить все поля, используя следующий код:

$username = "amos@contoso.onmicrosoft.com"
$password = "password."
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
$SiteURL = "https://contoso.sharepoint.com/sites/dev"
$ListName = "cal2"
$CSVPath = "C:\Temp\ListData.csv"
$ListDataCollection= @()

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $cred
$Counter = 0
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000

#Get all items from list
$ListItems | ForEach-Object {
        $ListItem  = Get-PnPProperty -ClientObject $_ -Property FieldValuesAsText
        $ListRow = New-Object PSObject
        $Counter++
        Get-PnPField -List $ListName | ForEach-Object {
            $ListRow | Add-Member -MemberType NoteProperty -name $_.InternalName -Value $ListItem[$_.InternalName]
            }
        Write-Progress -PercentComplete ($Counter / $($ListItems.Count)  * 100) -Activity "Exporting List Items..." -Status  "Exporting Item $Counter of $($ListItems.Count)"
        $ListDataCollection += $ListRow
}
#Export the result Array to CSV file
$ListDataCollection | Export-CSV $CSVPath -NoTypeInformation

Если вы хотите выводить настраиваемые столбцы,

$username = "amos@contoso.onmicrosoft.com"
$password = "password."
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
$SiteURL = "https://contoso.sharepoint.com/sites/dev"
$ListName = "cal2"
$CSVPath = "C:\Temp\ListData.csv"
$ListDataCollection= @()

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $cred
$Counter = 0
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000

foreach($item in $ListItems)
{
$ListDataCollection += New-Object PSObject -Property @{
                Title          = $Item["Title"]            
                Location = $Item["Location"]
                EventDate =  $Item["EventDate"]
                EndDate=  $Item["EndDate"]#you can add column you want to output
            }

}
#Export the result Array to CSV file
$ListDataCollection | Export-CSV $CSVPath -NoTypeInformation

https://www.sharepointdiary.com/2016/03/export-list-items-to-csv-in-sharepoint-online-using-powershell.html

0 голосов
/ 29 мая 2020

вы можете сделать это с помощью модуля pnp powershell: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

первое подключение к сайту:

Connect-PnPOnline -Url "{siteurl}"

элементы списка

повторяющиеся события хранятся в одном элементе списка. шаблон повторения сохраняется в поле «RecurrenceData». Итак, если вы просто хотите получить элементы в том виде, в каком они хранятся, вы можете сделать это с помощью следующей команды:

$listItems = Get-PnPListItem -List "{listtitle}"
$items = @()
foreach ($item in $listItems) {
    $items += [PSCustomObject]@{
        Title          = $item["Title"]
        Location       = $item["Location"]
        Category       = $item["Category"]
        EventDate      = $item["EventDate"]
        EndDate        = $item["EndDate"]
        fAllDayEvent   = $item["fAllDayEvent"]
        fRecurrence    = $item["fRecurrence"]
        RecurrenceID   = $item["RecurrenceID"]
        RecurrenceData = $item["RecurrenceData"]
    }
}
$items | Export-Csv -Path "items.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation

items.csv:

"Title";"Location";"Category";"EventDate";"EndDate";"fAllDayEvent";"fRecurrence";"RecurrenceID";"RecurrenceData"
"test";"asdf";"Treffen";"6/12/2020 9:00:00 AM";"6/12/2020 10:00:00 AM";"False";"False";;
"recurring";;;"6/15/2020 9:00:00 AM";"6/24/2020 10:00:00 AM";"False";"True";;"<recurrence><rule><firstDayOfWeek>mo</firstDayOfWeek><repeat><daily dayFrequency=""1"" /></repeat><repeatInstances>10</repeatInstances></rule></recurrence>"
"allday event";;;"6/26/2020 12:00:00 AM";"6/26/2020 11:59:00 PM";"True";"False";;

разделить повторяющиеся события

если вы хотите разделить повторяющиеся события, это усложняется. Я пробовал это с помощью sprestmethod "/_api/web/lists/GetByTitle('{listtitle}')/RenderListDataAsStream". в представлении xml вы можете определить диапазон дат для недели, месяца или года:

$view = [System.IO.File]::ReadAllText("$PSScriptRoot\view.year.xml")
$p = @{
  parameters = @{
    ViewXml = $view
  }
}
$result = Invoke-PnPSPRestMethod -Url "/_api/web/lists/GetByTitle('{listtitle}')/RenderListDataAsStream" -Method Post -Content $p
$items = $result.Row
$items | Export-Csv -Path "items-year.csv"
<View Type="CALENDAR" TabularView="FALSE" RecurrenceRowset="TRUE" Level="1" BaseViewID="2" ContentTypeID="0x">
  <Query>
    <Where>
      <DateRangesOverlap>
        <FieldRef Name="EventDate" />
        <FieldRef Name="EndDate" />
        <FieldRef Name="RecurrenceID" />
        <Value Type="DateTime">
          <Year />
        </Value>
      </DateRangesOverlap>
    </Where>
  </Query>
  <QueryOptions>
    <RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>
    <ExpandRecurrence>TRUE</ExpandRecurrence>
    <CalendarDate>2020-01-01T12:00:00Z</CalendarDate>
  </QueryOptions>
  <ViewFields>
    <FieldRef Name="EventDate" />
    <FieldRef Name="EndDate" />
    <FieldRef Name="fRecurrence" />
    <FieldRef Name="EventType" />
    <FieldRef Name="WorkspaceLink" />
    <FieldRef Name="Title" />
    <FieldRef Name="Location" />
    <FieldRef Name="Description" />
    <FieldRef Name="Workspace" />
    <FieldRef Name="MasterSeriesItemID" />
    <FieldRef Name="fAllDayEvent" />
  </ViewFields>
  <ViewData>
    <FieldRef Name="Title" Type="CalendarMonthTitle" />
    <FieldRef Name="Title" Type="CalendarWeekTitle" />
    <FieldRef Name="Location" Type="CalendarWeekLocation" />
    <FieldRef Name="Title" Type="CalendarDayTitle" />
    <FieldRef Name="Location" Type="CalendarDayLocation" />
  </ViewData>
  <Toolbar Type="Standard" />
</View>

в <CalendarDate>2020-01-01T12:00:00Z</CalendarDate> вы можете определить дату просмотра

...