question

RamachandranKrishnamoorthy-8642 avatar image
0 Votes"
RamachandranKrishnamoorthy-8642 asked RaytheonXie-MSFT commented

Company Users Directory in SharePoint Online

Hi Team,

I am trying to create a powerShell Script or an existing data to lookup in Azure AD and the required fields to be updated once in a day to the SharePoint List.

Required Information on the SharePoint List

  1. Display Name Attribute

  2. Email ID

  3. Telephone Number Attribute

  4. IP Phone Attribute

  5. Mobile

  6. Office

  7. Department

  8. Manager Name

These details should automatically fetch via a powershell command or a lookup in SharePoint List.

Let me know your thoughts.

Thanks,
Ram



office-sharepoint-onlinewindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @RamachandranKrishnamoorthy-8642 ,
You can refer to following script to retrieve all list items.

 #Config Parameters
 $SiteURL= "https://xxx.sharepoint.com/sites/abc"
 $ListName="test"
 $ItemTitle = "Display Name Attribute"
       
 #Setup Credentials to connect
 $Cred = Get-Credential
     
 Try {
     #Setup the context
     $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
     $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
         
     #Get the web and List
     $Web=$Ctx.Web
     $List=$web.Lists.GetByTitle($ListName)
        
     #Get a List item by its Title
     $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
     $Query.ViewXml = "@
     <View>
         <Query>
             <Where>
                 <Eq>
                     <FieldRef Name='Title' /><Value Type='Text'>$ItemTitle</Value>
                 </Eq>
             </Where>
         </Query>
     </View>"
      
     #Get All List Items matching the query
     $ListItems = $List.GetItems($Query)
     $Ctx.Load($ListItems)
     $Ctx.ExecuteQuery()
     
     Write-host "Total List Items:" $ListItems.count
        
     #Loop through each file in the library
     Foreach($Item in $ListItems)
     {
         Write-host -f Green $Item["Title"]
     }
 }
 Catch {
     write-host -f Red "Error:" $_.Exception.Message
 }


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RamachandranKrishnamoorthy-8642
Have you tried the solution I proposed?

If you have any questions or progress, you can contact me in time.

Looking forward to your reply

Have a lucky day!

Thanks,
Raytheon Xie

0 Votes 0 ·

Hi @RamachandranKrishnamoorthy-8642
Would you tell me whether your issue has been resolved or have any update?
I am looking forward to your reply.

Have a nice day!

Thanks,
Raytheon Xie

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi @RamachandranKrishnamoorthy-8642

This needs to be split into two sections. The first is querying Azure for the data via power shell. This article will help:

https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-powershell

Then you need to write the data into the share point list. List article will help you with this:

https://social.technet.microsoft.com/Forums/lync/en-US/42022287-7f3a-431b-acdd-8472ad8d9926/how-to-export-powershell-script-information-to-sharepoint?forum=sharepointgeneralprevious

Also this:

https://docs.microsoft.com/answers/questions/606290/pnp-powershell-upload-csv-to-sharepoint-list.html


I hope this answers your question.

Thanks.


--If the reply is helpful, please Upvote and Accept as answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RamachandranKrishnamoorthy-8642 avatar image
0 Votes"
RamachandranKrishnamoorthy-8642 answered RaytheonXie-MSFT commented

Hi Raytheon,

Splitting into two sections are more difficult here. We have some service accounts in AD without any telephone or mobile attribute. Extracting the data in excel brings up those service acccounts as well. I am looking into some other options as well.

Thanks,
Ram

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RamachandranKrishnamoorthy-8642 ,
You can try to add a filter which will exclude the users' telephone or mobile are empty. Use the IsNullorEmpty Method to Check if a String Variable Is Not Null or Empty in PowerShell.

0 Votes 0 ·

Hi @RamachandranKrishnamoorthy-8642 ,
Did the answer help you? If you have any question about the issue, please feel free to reply.

0 Votes 0 ·

Hi @RamachandranKrishnamoorthy-8642 ,
Would you tell me whether your issue has been resolved or have any update?
I am looking forward to your reply.

Have a nice day!

Thanks,
Raytheon Xie

0 Votes 0 ·