SOLVED

Unable to run across all users in Azure

%3CLINGO-SUB%20id%3D%22lingo-sub-1227051%22%20slang%3D%22en-US%22%3EUnable%20to%20run%20across%20all%20users%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1227051%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20trying%20to%20get%20powershell%20to%20update%20sharepoint%20which%20is%20working%20if%20i%20use%20an%20individual%20account%20please%20see%20the%20current%20script%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-Module%20SharePointPnPPowerShell*%20-ListAvailable%7C%20Select-Object%20Name%2CVersion%7C%20Sort-Object%20Version%20-Descending%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EInstall-Module%20SharePointPnPPowerShellOnline%3C%2FP%3E%3CP%3EUpdate-Module%20SharePointPnPPowerShell*%3C%2FP%3E%3CP%3EInstall-Module%20AzureAD%3C%2FP%3E%3CP%3EConnect-AzureAD%3C%2FP%3E%3CP%3E%24aaduser%20%3D%20Get-AzureADUser%20-ObjectId%20%22User1%40example.com%22%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EConnect-PnPOnline%20%E2%80%93Url%20%3CA%20href%3D%22https%3A%2F%2Fadmin.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fadmin.sharepoint.com%3C%2FA%3E%3C%2FP%3E%3CP%3Eif(''%20-ne%20%24aaduser.facsimileTelephoneNumber%20-and%20%24null%20-ne%20%24aaduser.facsimileTelephoneNumber)%20%7B%3CBR%20%2F%3ESet-PnPUserProfileProperty%20-Account%20%24aaduser.UserPrincipalName%20-Property%20'fax'%20-Value%20%24aaduser.facsimileTelephoneNumber%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20ever%20when%20i%20try%20to%20get%20this%20to%20run%20across%20all%20users%20in%20azure%20it%20fails%20to%20work%20the%20following%20script%20is%20this%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-Module%20SharePointPnPPowerShell*%20-ListAvailable%7C%20Select-Object%20Name%2CVersion%7C%20Sort-Object%20Version%20-Descending%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EInstall-Module%20SharePointPnPPowerShellOnline%3C%2FP%3E%3CP%3EUpdate-Module%20SharePointPnPPowerShell*%3C%2FP%3E%3CP%3EInstall-Module%20AzureAD%3C%2FP%3E%3CP%3EConnect-AzureAD%3C%2FP%3E%3CP%3E%24aadusers%20%3D%20Get-AzureADUser%20-All%20%24true%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EConnect-PnPOnline%20%E2%80%93Url%20%3CA%20href%3D%22https%3A%2F%2Fadmin.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fadmin.sharepoint.com%3C%2FA%3E%3C%2FP%3E%3CP%3Eif(''%20-ne%20%24aaduser.facsimileTelephoneNumber%20-and%20%24null%20-ne%20%24aaduser.facsimileTelephoneNumber)%20%7B%3CBR%20%2F%3ESet-PnPUserProfileProperty%20-Account%20%24aaduser.UserPrincipalName%20-Property%20'fax'%20-Value%20%24aaduser.facsimileTelephoneNumber%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20anyone%20point%20me%20in%20the%20correct%20direction%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1227051%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Active%20Directory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1236519%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20run%20across%20all%20users%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1236519%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F578263%22%20target%3D%22_blank%22%3E%40bluecoat2020%3C%2FA%3E%26nbsp%3BI%20think%20you%20are%20missing%20a%20foreach%20so%20you%20can%20loop%20through%20each%20user%20in%20%24aadusers.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EForeach(%24aaduser%20in%20%24aadusers)%0A%0A%20%7B%0A%20%20If(''%20-ne%20%24aaduser.facsimileTelephoneNumber%20-and%20%24null%20-ne%20%24aaduser.facsimileTelephoneNumber)%0A%20%20%20%7B%20%20%20%0A%20%20%20%20Set-PnPUserProfileProperty%20-Account%20%24aaduser.UserPrincipalName%20-Property%20'fax'%20-Value%20%24aaduser.facsimileTelephoneNumber%0A%20%20%20%7D%0A%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20Moreno%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1238458%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20run%20across%20all%20users%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1238458%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20very%20much%20that%20has%20worked%20really%20appreciated%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89674%22%20target%3D%22_blank%22%3E%40Erick%20A.%20Moreno%20R.%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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 (Occasional 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.