Missing a powershell command, what is it?

I'm removing users from the O365 recycle bin and I'm having a problem.  I did this last night and I recall the MS tech telling me I was missing one command, but he shared that in a char rather than in the notes and I didn't take it down.  Here's what I'm doing from my AZURE sync server on prem.

I open powershell and run these commands:

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

At this point, i run get-mailbox to ensure I'm returning mailboxes on my O365 server and I am getting a good return so I know I'm connected.  Than I try this:

Get-MsolUser –ReturnDeletedUsers | Remove-MsolUser –RemoveFromRecycleBin –Force

Here I get that get-msoluser is not a recognized command.  I recall yesterday that when we saw this the MS tech said, oh yeah, we have to run this and I want to say is was connect something but I can't remember.

Anyone know what I'm missing?

Thanks

Cliff
crp0499CEOAsked:
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.

FOXActive Directory/Exchange EngineerCommented:
Cliff- Use the below  command


Get-MsolUser –ReturnDeletedUsers | %{Remove-MsolUser -UserPrincipalName $_.UserPrincipalName –RemoveFromReycleBin -Confirm:$False}
1
crp0499CEOAuthor Commented:
same thing.  get-msoluser is not recognized
0
Vasil Michev (MVP)Commented:
Get-MsolUser is Azure AD PowerShell cmdlet, not Exchange Online. As in, you are connecting to Exchange Online with the example code above, instead you should use Connect-MsoLService first. Download/install the module from here: https://www.powershellgallery.com/packages/MSOnline/1.1.166.0
1

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
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

crp0499CEOAuthor Commented:
i have that module installed.  I am connected to my online exchange as I can pull a list of the mailboxes there.  your command connect-msolservice also returns an unrecognized command
0
crp0499CEOAuthor Commented:
you were bang on here.  When i successfully completed this last night, we did it from a different server that had the module installed.  I switched over to that server was it worked

Thank you
0
FOXActive Directory/Exchange EngineerCommented:
crp0499-
Do you have the Microsoft Azure Active Directory Module for Windows Powershell installed?
Also install Microsoft Online Services Sign-in Assistant

Then run the command again

Get-MsolUser –ReturnDeletedUsers | %{Remove-MsolUser -UserPrincipalName $_.UserPrincipalName –RemoveFromReycleBin -Confirm:$False}
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.