Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exception calling "ExecuteQuery" with "0" argument(s): "The HTTP service located at http://tetsjhsjsj22222/MetadataWebService.svc is unavailable. This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later."
- #Importing PowerShell Module
- Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
- #Authenticating User to SharePoint Online
- $username = "test@domainO365Dev.onmicrosoft.com"
- $Adminurl = "https://sp-admin.sharepoint.com/sites/Dev"
- $siteColUrl = "https://test365dev.sharepoint.com"
- #Logging Method for errors
- $DATE = get-date
- $LogPath = "logpath"
- $LogFileName = "LogFileName.log"
- $FilePath = $LogPath +"" + $LogFileName
- $logFileCreated = $False
- function write-log([string]$label, [string]$logMsg)
- {
- if($logFileCreated -eq $False)
- {
- write-host "Creating log file..."
- if((Test-Path -path $LogPath) -ne $True)
- {
- write-host"Provide proper values to LogPath folder" -ForegroundColor Red
- }
- else
- {
- Add-Content -Path $FilePath -Value $logHeader
- $script:logFileCreated = $True
- write-host "Log file created..."
- [string]$info = [System.String]::Format("[$Date] {0}: {1}",$label, $logMsg)
- Add-Content -Path $FilePath -Value $info
- }
- }
- else
- {
- [string]$info = [System.String]::Format("[$Date] {0}: {1}",$label, $logMsg)
- Add-Content -Path $FilePath -Value $info
- }
- }
- try
- {
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.UserProfiles.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- #Bind to site collection
- $password = Read-Host -Prompt "Enter password" -AsSecureString
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteColUrl)
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$Password)
- $Context.Credentials = $Creds
- Write-Host "Successfully connected.." -ForegroundColor Green
- #Retrieve lists
- $web = $Context.Web
- $Users = $Context.Web.SiteUsers
- $Context.Load($Users)
- $Context.Load($web)
- $Context.ExecuteQuery()
- $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
- Foreach ($User in $Users)
- {
- $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
- Write-Host "user profile value: " + $UserProfile
- $Context.ExecuteQuery()
- If ($UserProfile.Email -ne $null)
- {
- Write-Host "User:" $UserProfile.Email -ForegroundColor Green
- $UserProfile.UserProfileProperties
- //processing read data from list loop through 50 items
- }
- }
- }
- catch
- {
- write-log "Error: " $_.Exception.Message
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement