Forum Discussion
Using multiple variables against single command
- Jun 03, 2020
The script looks OK, although you need to move the $OneDriveUrl part inside the loop (otherwise it will always return the same value). I would suggest generating a list of individual ODFB URLs first, then combining it with the username in a CSV file. That way you can simply reference the different values via say $_.UserName, $_.OneDriveUrl and so on.
The script looks OK, although you need to move the $OneDriveUrl part inside the loop (otherwise it will always return the same value). I would suggest generating a list of individual ODFB URLs first, then combining it with the username in a CSV file. That way you can simply reference the different values via say $_.UserName, $_.OneDriveUrl and so on.
- charlie4872Jun 03, 2020Brass Contributor
Thanks for the response VasilMichev I tried moving the $OneDriveUrl portion of the script inside the loop and no dice. Although I may have it wrong. I have to admit I am not a Powershell wiz by any means. I have change the script like below...
$username = get-content c:\temp\users.txt $newadmin = Read-Host 'Enter New Admin' foreach ($user in $username){ $OneDriveUrl = Get-PnPUserProfileProperty -Account $username | select-object PersonalUrl Set-SPOUser -Site $OneDriveUrl.PersonalUrl -LoginName $newadmin -IsSiteCollectionAdmin $True -ErrorAction SilentlyContinue}- VasilMichevJun 04, 2020MVP
Inside the loop, you should be using $user instead of $username.
- charlie4872Jun 04, 2020Brass Contributor
Thanks VasilMichev that was my issue. I confirmed its working now. Thank you very much for you help!