Jump to content

Recommended Posts

Posted

We're about to rename the UPNs of all staff in O365 so I'm trying to script it. But I can't get the PSSession to connect without prompting for credentials. Is this possible?

 

$currUsername = "SmithJ"
$newUsername = "John.Smith"
       
$secpasswd = ConvertTo-SecureString "Password" -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential ("[email protected]", $secpasswd)


$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-msolservice
Set-MsolUserPrincipalName -UserPrincipalName "[email protected]" -NewUserPrincipalName "[email protected]"

 

Bonus Error:

This pops up when Import-PSSession is called.

WARNING: The names of some imported commands from the module 'tmp_fywafn3s.bq2' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

Verbs look fine to me.

Posted (edited)

I use the following to connect and i've not had a problem before.

 

$username = "[email protected]"
$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$MsolCred = New-Object -TypeName System.Management.Automation.PSCredential ($username, $password)

Connect-MsolService -Credential $MsolCred

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $MsolCred -Authentication Basic -AllowRedirection
Import-PSSession $Session

 

It looks exactly the same as yours apart from i'm also connecting to exchange online, which you shouldn't need to do.

Edited by Marshall_IT
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...