Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Update InactiveUsersLast90Days.ps1
Browse files Browse the repository at this point in the history
Changed the code to support MFA sign-in
  • Loading branch information
EricVanAken committed Jun 24, 2019
1 parent ae18aae commit baa3018
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions InactiveUsersLast90Days.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import-module MSOnline
#Import MSOline Module
import-module MSOnline
#Import Exchange Online Module
Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse).FullName | ?{ $_ -notmatch "_none_" } | select -First 1)

#Let's get us an admin cred!
$userCredential = Get-Credential

#This connects to Azure Active Directory
Connect-MsolService -Credential $userCredential
$ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $userCredential -Authentication Basic -AllowRedirection
Import-PSSession $ExoSession
#Set admin UPN
$UPN = 'user@domain.com'

#This connects to Azure Active Directory & Exchange Online
Connect-MsolService
$EXOSession = New-ExoPSSession -UserPrincipalName $UPN
Import-PSSession $EXOSession -AllowClobber

$startDate = (Get-Date).AddDays(-90).ToString('MM/dd/yyyy')
$endDate = (Get-Date).ToString('MM/dd/yyyy')
Expand Down

4 comments on commit baa3018

@haynie777
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code produces errors....
Import-Module : Cannot bind argument to parameter 'Name' because it is null.
O365InactiveUsersLast90Days.ps1:4 char:16

  • ... port-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0" ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Import-Module], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModuleCommand

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
WARNING: The names of some imported commands from the module 'tmp_csetflpe.lzp' 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.

@RaviD-Git
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Friends, Is there any place to get help on how to run this script. Am getting errors
image

@PsychoData
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if you have run/installed the Exchange Online Hybrid Tool.

to get it go to https://aka.ms/ExoPSHybrid

However, this will mean everyone is connecting the MFA Capable way and you can't do things like pass it a credential,

The re-connection capabilities are also severely impaired compared with a properly opened Exchange Online Hybrid Shell.

@cristiandurant
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run the script but the result are all domain users. For any reason the script not take the date.

Please sign in to comment.