Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #Clear Error Log
  2. $Error.Clear()
  3.  
  4. Import-Module 'C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll'
  5. Import-Module 'C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll'
  6. Import-Module "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Taxonomy.dll"
  7.  
  8. Write-Host ""
  9. write-host "## SharePoint Online List to JSON converter ##" -ForegroundColor DarkYellow
  10.  
  11.  
  12. # Constant settings, leave blank to specify at runtime
  13. $siteroot = ""
  14. $sitesubsite = ""
  15. $ListName = ""
  16. $AdminUsername = ""
  17.  
  18. #Connect to MSOL and Exchange Online. Comment out the MSOL session bits to ignore the exchange bits
  19. $MSOLSession = $Null
  20. $PSCredential = $Null
  21. $0365Credential = $Null
  22. #Determine Enviroment
  23. if ($Env:COMPUTERNAME -eq "CLIENT" -and $Env:USERNAME -eq "CLIENT") {
  24. write-verbose "Azure Automation Services Environment Detected"
  25.  
  26. #use Azure Auotmation Services Stored Credentials
  27. $PSCredential = Get-AutomationPSCredential -Name Office365AzureAdmin
  28. $0365Credential = Get-AutomationPSCredential -Name ExchangeOnlineAdmin
  29. } else {
  30. write-host "Local Environment Detected"
  31. }
  32.  
  33. $AdminName = [Environment]::UserName
  34. $PCName = $Env:COMPUTERNAME
  35. $AdminPassword = $null
  36.  
  37. if ($AdminUsername -eq "")
  38. {
  39. Write-Host "Username couldn't be detected" -ForegroundColor Red
  40. $AdminUsername = Read-Host "Enter username:"
  41. }
  42.  
  43. if ($siteroot -eq "")
  44. {
  45. $siteroot = Read-Host "Enter site root (ex https://test.sharepoint.com):"
  46. }
  47.  
  48. if ($ListName -eq "")
  49. {
  50. $ListName = Read-Host "Enter list title (ex 'Contacts list'):"
  51. }
  52.  
  53. if ($sitesubsite -eq "")
  54. {
  55. $sitesubsite = Read-Host "Enter subsite (ex /sites/teamsite):"
  56. }
  57.  
  58. $FileName = $AdminName + $PCName
  59. $CredsFile = ".EncryptedPasswords$FileName-O365Password.txt"
  60. $FileExists = Test-Path $CredsFile
  61.  
  62. if ($FileExists -eq $false) {
  63. Write-Host "Credential file not found. Enter password for $AdminName :" -ForegroundColor Red
  64. Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File $CredsFile
  65. $AdminPassword = get-content $CredsFile | convertto-securestring
  66.  
  67. } else {
  68. Write-Host 'Using your stored credential file' -ForegroundColor Green
  69. $AdminPassword = get-content $CredsFile | convertto-securestring
  70. }
  71.  
  72. #Get the Client Context and Bind the Site Collection
  73. $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteroot + $sitesubsite)
  74.  
  75. #Authenticate
  76. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUsername, $AdminPassword)
  77. $context.Credentials = $credentials
  78.  
  79. #Lookup Source Address
  80. $rootWeb = $Context.Web
  81. $List = $rootWeb.lists.getByTitle($ListName)
  82. $fields = $List.Fields;
  83. $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
  84.  
  85. #Load the List
  86. $Context.Load($rootWeb)
  87. $Context.load($List)
  88. $Context.Load($ListItems)
  89. $context.Load($fields)
  90. $Context.ExecuteQuery()
  91.  
  92. Write-Host "List items are"
  93. foreach ($item in $ListItems)
  94. {
  95. Write-Host "----------------------------------------------"
  96. Write-Host "Display Title: " $item["Title"]
  97. Write-Host "Setting:" $item["Setting"]
  98. Write-Host "File Description:" $item["File Description"]
  99. Write-Host "Health Area:" $item["Health_x0020_Area"]
  100. Write-Host "Resource Type: " $item["Resource_x0020_Type"]
  101. Write-Host "Currently active: " $item["Currently_x0020_active_x003f_"]
  102. Write-Host "External file path: " $item["External_x0020_file_x0020_path"]
  103. Write-Host "----------------------------------------------"
  104. }
  105.  
  106. Write-Host $ListItems | ConvertTo-Json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement