• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 50
  • Last Modified:

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
0
crp0499
Asked:
crp0499
  • 3
  • 2
1 Solution
 
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
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now