Advertisement
sharepointmatthew

Untitled

Mar 31st, 2017
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_15.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
  2. Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_15.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll"
  3.  
  4.  
  5.  
  6. $webUrl = "https://noteworthy.sharepoint.com/sites/USPTODSBDeployment/"
  7. $listName = "DSBUserAssetInformation"
  8. $username = "admin@noteworthy.onmicrosoft.com"
  9. $password = Read-Host -Prompt "Enter your Password" -AsSecureString
  10. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
  11. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
  12. $ctx.Credentials = $credentials
  13. #$currentParent = ''
  14. $web = $ctx.Web
  15. $ctx.Load($web)
  16. $ctx.Load($ctx.Web.Lists)
  17. $ctx.ExecuteQuery()
  18. $list = $ctx.Web.Lists.GetByTitle("DSBUserAssetInformation")
  19. $ctx.Load($list)
  20.  
  21. #Start debugging log and path to import data
  22. $docSetExcelSpreadsheet = Import-Csv C:\Users\mbailey3\Documents\Projects\DSBDeploymentProject\PretendDataCSV1.csv -Delimiter ','
  23. $rightNow = Get-Date -format MM-dd-yy-HH-mm-ss
  24.  
  25. $ErrorFileName = "C:\Users\mbailey3\Documents\Projects\DSBDeploymentProject\ErrorLogs" + $rightNow + ".txt"
  26. ForEach ($employee in $employeeAssetExcelSpreadsheet) {
  27. try {
  28.  
  29. $listItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
  30. $item = $list.AddItem($listItemInfo)
  31. $item["TITLE"] = $employee.TITLE
  32. $item["ASSETID"] = $employee.ASSETID
  33. $item["ITSM_ORGANIZATION"] = $employee.ITSM_ORGANIZATION
  34. $item["PAO"] = $employee.PAO
  35. $item["PC"] = $employee.PC
  36. $item["ASSET_EMPL_ID"] = $employee.ASSET_EMPL_ID
  37. $item["PTO_LOGIN_ID"] = $employee.PTO_LOGIN_ID
  38. $item["ASSET_DESCRIPTION"] = $employee.ASSET_DESCRIPTION
  39. write-host $item.FieldValues
  40.  
  41. } catch {
  42. $ErrorMessage = $_.Exception.Message
  43. $FailedItem = $_.Exception.ItemName
  44. write-host "$ErrorMessage $FailedItem"
  45. Add-Content $ErrorFileName "`n $ErrorMessage $FailedItem"
  46. }
  47. }
  48. write-host "Fin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement