Insert/Add Current Date item to SharePoint Online using PowerShell
ADR Tutorials
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
$SiteURL = "https://CompanyName.sharepoint.com/sites/DesarrolloSharepoint/"
$ListName="Datos"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString "Password" -AsPlainText -Force
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("user@CompanyName.onmicrosoft.com", $securePassword)
$Web = $Context.Web
$List = $web.get_lists().getByTitle($ListName)
$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$CurrentDay = Get-Date -Format "dd"
$CurrentMonth = Get-Date -Format "MM"
$CurrentYear = Get-Date -Format "yyyy"
$currentThread = [System.Threading.Thread]::CurrentThread
$dateToStore = $CurrentThread.CurrentCulture.Clone()
$dateToStore.DateTimeFormat.ShortDatePattern = 'dd-MM-yyyy'
$dateToStore_temp = $CurrentDay + "-" + $CurrentMonth + "-" + $CurrentYear
$dateToStore = Get-Date $dateToStore_temp
$listItem = $list.addItem($itemCreateInfo)
$listItem.set_item('Title', 'Item Title' + 'Day: ' + $CurrentDay1 + ' Month: ' + $CurrentMonth)
$listItem.set_item('Description', $CurrentDay + $CurrenttMonth)
$listItem.set_item('CurrentDay', $CurrentDay )
$listItem.set_item('CurrentMonth', $CurrentMonth )
$listItem.set_item('Date', $dateToStore )
$listItem.update();
$Context.Load($listItem)
$Context.ExecuteQuery()
miércoles, 26 de febrero de 2020
lunes, 24 de febrero de 2020
Sharepoint Online PowerShell Script add item list
Sharepoint Online PowerShell Script add item list
Error:
Excepción al llamar a "ExecuteQuery" con los argumentos "0": "The sign-in name or password does not match one in the
Microsoft account system."
ADR Tutorials
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
$SiteURL = "https://CompanySite.sharepoint.com/sites/YourSite/"
$ListName="Datos"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString "Type password Here" -AsPlainText -Force
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("user@CompanySite.com", $securePassword)
$Web = $Context.Web
$List = $web.get_lists().getByTitle($ListName)
$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$CurrentDay1 = Get-Date -Format "dd"
$CurrenttMonth = Get-Date -Format "MM"
$listItem = $list.addItem($itemCreateInfo)
$listItem.set_item('Title', 'Item Title')
$listItem.set_item('Description', $CurrentDay1 + '-' + $CurrenttMonth)
$listItem.update();
$Context.Load($listItem)
$Context.ExecuteQuery()
Suscribirse a:
Entradas (Atom)