SOLVED

Unable to run across all users in Azure

Copper Contributor

Hi 

 

Just trying to get powershell to update sharepoint which is working if i use an individual account please see the current script

 

Get-Module SharePointPnPPowerShell* -ListAvailable| Select-Object Name,Version| Sort-Object Version -Descending


Install-Module SharePointPnPPowerShellOnline

Update-Module SharePointPnPPowerShell*

Install-Module AzureAD

Connect-AzureAD

$aaduser = Get-AzureADUser -ObjectId "User1@example.com"


Connect-PnPOnline –Url https://admin.sharepoint.com

if('' -ne $aaduser.facsimileTelephoneNumber -and $null -ne $aaduser.facsimileTelephoneNumber) {
Set-PnPUserProfileProperty -Account $aaduser.UserPrincipalName -Property 'fax' -Value $aaduser.facsimileTelephoneNumber

 

How ever when i try to get this to run across all users in azure it fails to work the following script is this 

 

Get-Module SharePointPnPPowerShell* -ListAvailable| Select-Object Name,Version| Sort-Object Version -Descending


Install-Module SharePointPnPPowerShellOnline

Update-Module SharePointPnPPowerShell*

Install-Module AzureAD

Connect-AzureAD

$aadusers = Get-AzureADUser -All $true


Connect-PnPOnline –Url https://admin.sharepoint.com

if('' -ne $aaduser.facsimileTelephoneNumber -and $null -ne $aaduser.facsimileTelephoneNumber) {
Set-PnPUserProfileProperty -Account $aaduser.UserPrincipalName -Property 'fax' -Value $aaduser.facsimileTelephoneNumber

 

Could anyone point me in the correct direction 

 

Thank you 

2 Replies
best response confirmed by bluecoat2020 (Copper Contributor)
Solution

@bluecoat2020 I think you are missing a foreach so you can loop through each user in $aadusers. 

 

Foreach($aaduser in $aadusers)

 {
  If('' -ne $aaduser.facsimileTelephoneNumber -and $null -ne $aaduser.facsimileTelephoneNumber)
   {   
    Set-PnPUserProfileProperty -Account $aaduser.UserPrincipalName -Property 'fax' -Value $aaduser.facsimileTelephoneNumber
   }
 }

Regards

Erick Moreno

Thank you very much that has worked really appreciated  @Erick A. Moreno R. 

1 best response

Accepted Solutions
best response confirmed by bluecoat2020 (Copper Contributor)
Solution

@bluecoat2020 I think you are missing a foreach so you can loop through each user in $aadusers. 

 

Foreach($aaduser in $aadusers)

 {
  If('' -ne $aaduser.facsimileTelephoneNumber -and $null -ne $aaduser.facsimileTelephoneNumber)
   {   
    Set-PnPUserProfileProperty -Account $aaduser.UserPrincipalName -Property 'fax' -Value $aaduser.facsimileTelephoneNumber
   }
 }

Regards

Erick Moreno

View solution in original post