Guest User

Untitled

a guest
Nov 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. # Create Context for PowerShell Modules and User Credentials (connection to O365, O365 Admin)
  2. $FunctionName = 'AddAzureADUser'
  3.  
  4. # Define Modules
  5. $PnPModuleName = 'SharePointPnPPowerShellOnline'
  6. $PnPVersion = '2.20.1711.0'
  7. $AzureADModuleName = 'AzureAD'
  8. $AzureADVersion = '2.0.0.131'
  9. $MSOLModuleName ='MSOnline'
  10. $MSOLVersion ='1.1.166.0'
  11.  
  12. $username = $Env:user
  13. $pw = $Env:password
  14.  
  15. # Import PS modules
  16. $AzureADModulePath = "D:\home\site\wwwroot\$FunctionName\bin\$AzureADModuleName\$AzureADVersion\$AzureADModuleName.psd1"
  17. $MSOLModulePath = "D:\home\site\wwwroot\$FunctionName\bin\$MSOLModuleName\$MSOLVersion\$MSOLModuleName.psd1"
  18. $PnPModulePath = "D:\home\site\wwwroot\$FunctionName\bin\$PnPModuleName\$PnPVersion\$PnPModuleName.psd1"
  19. $res = "D:\home\site\wwwroot\$FunctionName\bin"
  20.  
  21. Import-Module $AzureADModulePath
  22. Import-Module $PnPModulePath
  23. Import-Module $MSOLModulePath
  24.  
  25. # Build Credentials
  26. $keypath = "D:\home\site\wwwroot\$FunctionName\bin\keys\PassEncryptKey.key"
  27. $pwfile = @(Get-Content $keypath)[0]
  28. $secpassword = $pw | ConvertTo-SecureString -Key $pwfile
  29. $credentials= New-Object System.Management.Automation.PSCredential ($username, $secpassword)
  30.  
  31. # Your Tenant ID
  32. $tenant = "TENANT ID"
  33.  
  34. # Connect to MSOL
  35. Connect-MsolService -Credential $credentials
  36.  
  37. # Connect to SharePoint Online Service
  38. Connect-PnPOnline -Url $url -Credentials $credentials
  39. $item = Get-PNPListItem -List Lists/$listTitle -Id $itemId
  40.  
  41. # Connect to Azure AD
  42. Connect-AzureAD -TenantId $tenant -Credential $credentials # Connect-AzureAD clears the password
Add Comment
Please, Sign In to add comment