Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_15.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
- 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"
- $webUrl = "https://noteworthy.sharepoint.com/sites/USPTODSBDeployment/"
- $listName = "DSBUserAssetInformation"
- $username = "admin@noteworthy.onmicrosoft.com"
- $password = Read-Host -Prompt "Enter your Password" -AsSecureString
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
- $ctx.Credentials = $credentials
- #$currentParent = ''
- $web = $ctx.Web
- $ctx.Load($web)
- $ctx.Load($ctx.Web.Lists)
- $ctx.ExecuteQuery()
- $list = $ctx.Web.Lists.GetByTitle("DSBUserAssetInformation")
- $ctx.Load($list)
- #Start debugging log and path to import data
- $docSetExcelSpreadsheet = Import-Csv C:\Users\mbailey3\Documents\Projects\DSBDeploymentProject\PretendDataCSV1.csv -Delimiter ','
- $rightNow = Get-Date -format MM-dd-yy-HH-mm-ss
- $ErrorFileName = "C:\Users\mbailey3\Documents\Projects\DSBDeploymentProject\ErrorLogs" + $rightNow + ".txt"
- ForEach ($employee in $employeeAssetExcelSpreadsheet) {
- try {
- $listItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
- $item = $list.AddItem($listItemInfo)
- $item["TITLE"] = $employee.TITLE
- $item["ASSETID"] = $employee.ASSETID
- $item["ITSM_ORGANIZATION"] = $employee.ITSM_ORGANIZATION
- $item["PAO"] = $employee.PAO
- $item["PC"] = $employee.PC
- $item["ASSET_EMPL_ID"] = $employee.ASSET_EMPL_ID
- $item["PTO_LOGIN_ID"] = $employee.PTO_LOGIN_ID
- $item["ASSET_DESCRIPTION"] = $employee.ASSET_DESCRIPTION
- write-host $item.FieldValues
- } catch {
- $ErrorMessage = $_.Exception.Message
- $FailedItem = $_.Exception.ItemName
- write-host "$ErrorMessage $FailedItem"
- Add-Content $ErrorFileName "`n $ErrorMessage $FailedItem"
- }
- }
- write-host "Fin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement