Force user to change password on next login.

What I am looking for is some help on the following script but for it to read a CSV file instead of individual

Set-MsolUserPassword -UserPrincipalName user@domain.com -ForceChangePasswordOnly $true -ForceChangePassword $true

The reason i am after this is so I can force groups of people rather than all.

I am in a CLOUD OFFICE 365 environment with no AD or Hybrid.

Thanks

John
John DaviesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex GreenProject Systems EngineerCommented:
$Users = Get-content C:\temp\source.txt
Foreach ($User in $Users) { Set-MsolUserPassword -UserPrincipalName $User -ForceChangePasswordOnly $true -ForceChangePassword $true}

Open in new window


That should do it, you'll have to have the user@domain.com in the text file

If you really want to use a csv

$Users = import-csv C:\temp\source.csv
Foreach ($User in $Users) { Set-MsolUserPassword -UserPrincipalName $User -ForceChangePasswordOnly $true -ForceChangePassword $true}

Open in new window

0
Vasil Michev (MVP)Commented:
Assuming you have a blabla.csv with a column UPN to designate the users:

Improt-CSV blabla.csv | % { Set-MsolUserPassword -UserPrincipalName $_.UPN -ForceChangePasswordOnly $true -ForceChangePassword $true }

Open in new window

0
oBdACommented:
All you need is a loop over the file contents.
Flat file, one UPN per line:
Get-Content -Path "C:\Temp\userlist.txt" | ForEach-Object {
	Set-MsolUserPassword -UserPrincipalName $_ -ForceChangePasswordOnly $true -ForceChangePassword $true
}

Open in new window

Csv with a column 'UPN':
Import-Csv -Path "C:\Temp\userlist.txt" | ForEach-Object {
	Set-MsolUserPassword -UserPrincipalName $_.UPN -ForceChangePasswordOnly $true -ForceChangePassword $true
}

Open in new window

0
Challenges in Government Cyber Security

Has cyber security been a challenge in your government organization? Are you looking to improve your government's network security? Learn more about how to improve your government organization's security by viewing our on-demand webinar!

Alex GreenProject Systems EngineerCommented:
I BEAT oBdA!!!!!!

and our code is pretty much identical, I feel pride, immense amounts of pride :D

I'm not a shadow on him though... Or her, you never know.
0
John DaviesAuthor Commented:
Lol Alex,

Just run the code to a CSV that has one column UserPrincipalName and get the following error, what I was getting before :-(

Set-MsolUserPassword : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
At C:\Users\John\Desktop\Passwords\Change2016.ps1:2 char:42
+     Set-MsolUserPassword -UserPrincipalName $_.UPN -ForceChangePasswo ...
+                                             ~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-MsolUserPassword], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Online.Administration.Automation.SetUserPa
   ssword
0
oBdACommented:
If the column is named UserPrincipalName, then you have to change the loop variable's ($_) property accordingly:
Import-Csv -Path "C:\Temp\userlist.txt" | ForEach-Object {
	Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName -ForceChangePasswordOnly $true -ForceChangePassword $true
} 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John DaviesAuthor Commented:
Bingo, that was it.

Thank you all for your help, really really appreciated!

Have a great day guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.