mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-18 00:45:19 +00:00
.
This commit is contained in:
parent
9fe919b43f
commit
f4b2a05f68
@ -1,85 +1,85 @@
|
|||||||
#Connect to Exchange Online PowerShell
|
#Connect to Exchange Online PowerShell
|
||||||
Param
|
Param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[switch]$Disconnect,
|
[switch]$Disconnect,
|
||||||
[switch]$MFA,
|
[switch]$MFA,
|
||||||
[string]$UserName,
|
[string]$UserName,
|
||||||
[string]$Password
|
[string]$Password
|
||||||
)
|
)
|
||||||
#Disconnect existing sessions
|
#Disconnect existing sessions
|
||||||
if($Disconnect.IsPresent)
|
if($Disconnect.IsPresent)
|
||||||
{
|
{
|
||||||
Get-PSSession | Remove-PSSession
|
Get-PSSession | Remove-PSSession
|
||||||
Write-Host All sessions in the current window has been removed. -ForegroundColor Yellow
|
Write-Host All sessions in the current window has been removed. -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
#Connect Exchnage Online with MFA
|
#Connect Exchnage Online with MFA
|
||||||
elseif($MFA.IsPresent)
|
elseif($MFA.IsPresent)
|
||||||
{
|
{
|
||||||
#Check for MFA mosule
|
#Check for MFA mosule
|
||||||
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
||||||
If ($MFAExchangeModule -eq $null)
|
If ($MFAExchangeModule -eq $null)
|
||||||
{
|
{
|
||||||
Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow
|
Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow
|
||||||
Write-Host You can install module using below blog : `nLink `nOR you can install module directly by entering "Y"`n
|
Write-Host You can install module using below blog : `nLink `nOR you can install module directly by entering "Y"`n
|
||||||
$Confirm= Read-Host Are you sure you want to install module directly? [Y] Yes [N] No
|
$Confirm= Read-Host Are you sure you want to install module directly? [Y] Yes [N] No
|
||||||
if($Confirm -match "[yY]")
|
if($Confirm -match "[yY]")
|
||||||
{
|
{
|
||||||
Write-Host Yes
|
Write-Host Yes
|
||||||
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
$Confirmation= Read-Host Have you installed Exchange Online MFA Module? [Y] Yes [N] No
|
$Confirmation= Read-Host Have you installed Exchange Online MFA Module? [Y] Yes [N] No
|
||||||
if($Confirmation -match "[yY]")
|
if($Confirmation -match "[yY]")
|
||||||
{
|
{
|
||||||
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
||||||
If ($MFAExchangeModule -eq $null)
|
If ($MFAExchangeModule -eq $null)
|
||||||
{
|
{
|
||||||
Write-Host Exchange Online MFA module is not available -ForegroundColor red
|
Write-Host Exchange Online MFA module is not available -ForegroundColor red
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host Exchange Online PowerShell Module is required
|
Write-Host Exchange Online PowerShell Module is required
|
||||||
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Importing Exchange MFA Module
|
#Importing Exchange MFA Module
|
||||||
write-host aaaa
|
write-host aaaa
|
||||||
. "$MFAExchangeModule"
|
. "$MFAExchangeModule"
|
||||||
Connect-EXOPSSession -WarningAction SilentlyContinue | Out-Null
|
Connect-EXOPSSession -WarningAction SilentlyContinue | Out-Null
|
||||||
}
|
}
|
||||||
#Connect Exchnage Online with Non-MFA
|
#Connect Exchnage Online with Non-MFA
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(($UserName -ne "") -and ($Password -ne ""))
|
if(($UserName -ne "") -and ($Password -ne ""))
|
||||||
{
|
{
|
||||||
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
||||||
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$Credential=Get-Credential -Credential $null
|
$Credential=Get-Credential -Credential $null
|
||||||
}
|
}
|
||||||
|
|
||||||
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
|
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
|
||||||
Import-PSSession $Session -DisableNameChecking -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
Import-PSSession $Session -DisableNameChecking -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
#Check for connectivity
|
#Check for connectivity
|
||||||
if(!($Disconnect.IsPresent)){
|
if(!($Disconnect.IsPresent)){
|
||||||
If ((Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }) -ne $null)
|
If ((Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }) -ne $null)
|
||||||
{
|
{
|
||||||
Write-Host `nSuccessfully connected to Exchange Online
|
Write-Host `nSuccessfully connected to Exchange Online
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host `nUnable to connect to Exchange Online. Error occurred -ForegroundColor Red
|
Write-Host `nUnable to connect to Exchange Online. Error occurred -ForegroundColor Red
|
||||||
}}
|
}}
|
||||||
@ -1,319 +1,319 @@
|
|||||||
<#
|
<#
|
||||||
=============================================================================================
|
=============================================================================================
|
||||||
Name: PrivateChannelManagement
|
Name: PrivateChannelManagement
|
||||||
Description: This script performs Private Channel related management actions and reporting
|
Description: This script performs Private Channel related management actions and reporting
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
Released date: 18/11/2019
|
Released date: 18/11/2019
|
||||||
website: blog.admindroid.com
|
website: blog.admindroid.com
|
||||||
Script by: AdminDroid Team (Proud Creators of AdminDroid Office 365 Reporting Tool)
|
Script by: AdminDroid Team (Proud Creators of AdminDroid Office 365 Reporting Tool)
|
||||||
|
|
||||||
|
|
||||||
To run the script
|
To run the script
|
||||||
./PrivateChannelManagement.ps1
|
./PrivateChannelManagement.ps1
|
||||||
|
|
||||||
To schdeule/run the script by explicitly mentioning credential
|
To schdeule/run the script by explicitly mentioning credential
|
||||||
./PrivateChannelManagement.ps1 -UserName <UserName> -Password <Password>
|
./PrivateChannelManagement.ps1 -UserName <UserName> -Password <Password>
|
||||||
|
|
||||||
To run the script with MFA enabled account
|
To run the script with MFA enabled account
|
||||||
./PrivateChannelManagement.ps1 -MFA
|
./PrivateChannelManagement.ps1 -MFA
|
||||||
============================================================================================
|
============================================================================================
|
||||||
#>
|
#>
|
||||||
|
|
||||||
#Accept input paramenters
|
#Accept input paramenters
|
||||||
param(
|
param(
|
||||||
[string]$UserName,
|
[string]$UserName,
|
||||||
[string]$Password,
|
[string]$Password,
|
||||||
[switch]$MFA,
|
[switch]$MFA,
|
||||||
[int]$Action
|
[int]$Action
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#install latest Microsoft Teams module from PowerShell Test Gallery
|
#install latest Microsoft Teams module from PowerShell Test Gallery
|
||||||
$Module=Get-Module -Name MicrosoftTeams -ListAvailable
|
$Module=Get-Module -Name MicrosoftTeams -ListAvailable
|
||||||
if($Module.count -eq 0)
|
if($Module.count -eq 0)
|
||||||
{
|
{
|
||||||
$Confirm= Read-Host Are you sure you want to install Microsoft Teams module? [Y] Yes [N] No
|
$Confirm= Read-Host Are you sure you want to install Microsoft Teams module? [Y] Yes [N] No
|
||||||
if($Confirm -match "[y]")
|
if($Confirm -match "[y]")
|
||||||
{
|
{
|
||||||
Register-PSRepository -Name PSGalleryInt -SourceLocation https://www.poshtestgallery.com/ -InstallationPolicy Trusted
|
Register-PSRepository -Name PSGalleryInt -SourceLocation https://www.poshtestgallery.com/ -InstallationPolicy Trusted
|
||||||
Install-Module -Name MicrosoftTeams -Repository PSGalleryInt -Force
|
Install-Module -Name MicrosoftTeams -Repository PSGalleryInt -Force
|
||||||
Write-Host Installing Microsoft Teams Module...
|
Write-Host Installing Microsoft Teams Module...
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host `nNeed Microsoft Teams PowerShell module. Please install the latest module from PowerShell Test Gallery -ForegroundColor Yellow
|
Write-Host `nNeed Microsoft Teams PowerShell module. Please install the latest module from PowerShell Test Gallery -ForegroundColor Yellow
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#Check for latest Microsoft Teams PowerShell Module
|
#Check for latest Microsoft Teams PowerShell Module
|
||||||
elseif((Get-module -Name MicrosoftTeams -ListAvailable).version -lt "1.0.18")
|
elseif((Get-module -Name MicrosoftTeams -ListAvailable).version -lt "1.0.18")
|
||||||
{
|
{
|
||||||
Write-Host `nTo manage Private Channel, you must install lastest version of MicrosoftTeams PowerShell module from PowerShell Test Gallery
|
Write-Host `nTo manage Private Channel, you must install lastest version of MicrosoftTeams PowerShell module from PowerShell Test Gallery
|
||||||
$Confirm= Read-Host `nAre you sure you want to uninstall old version ? [Y] Yes [N] No
|
$Confirm= Read-Host `nAre you sure you want to uninstall old version ? [Y] Yes [N] No
|
||||||
if($Confirm -match "[y]")
|
if($Confirm -match "[y]")
|
||||||
{
|
{
|
||||||
Uninstall-Module -Name MicrosoftTeams
|
Uninstall-Module -Name MicrosoftTeams
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host Please install latest version of Microsoft Teams PowerShell module from PowerShell Test Gallery -ForegroundColor Yellow
|
Write-Host Please install latest version of Microsoft Teams PowerShell module from PowerShell Test Gallery -ForegroundColor Yellow
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
$Confirm= Read-Host `nAre you sure you want to install latest version of Microsoft Teams module? [Y] Yes [N] No
|
$Confirm= Read-Host `nAre you sure you want to install latest version of Microsoft Teams module? [Y] Yes [N] No
|
||||||
if($Confirm -match "[y]")
|
if($Confirm -match "[y]")
|
||||||
{
|
{
|
||||||
Register-PSRepository -Name PSGalleryInt -SourceLocation https://www.poshtestgallery.com/ -InstallationPolicy Trusted
|
Register-PSRepository -Name PSGalleryInt -SourceLocation https://www.poshtestgallery.com/ -InstallationPolicy Trusted
|
||||||
Install-Module -Name MicrosoftTeams -Repository PSGalleryInt -Force
|
Install-Module -Name MicrosoftTeams -Repository PSGalleryInt -Force
|
||||||
Write-Host Installing Microsoft Teams Module...
|
Write-Host Installing Microsoft Teams Module...
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host `nPlease install latest version of Microsoft Teams PowerShell module from PowerShell Test Gallery -ForegroundColor Yellow
|
Write-Host `nPlease install latest version of Microsoft Teams PowerShell module from PowerShell Test Gallery -ForegroundColor Yellow
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#Check Skype for Business Online module
|
#Check Skype for Business Online module
|
||||||
$Module=Get-Module -Name SkypeOnlineConnector -ListAvailable
|
$Module=Get-Module -Name SkypeOnlineConnector -ListAvailable
|
||||||
if($Module.count -eq 0)
|
if($Module.count -eq 0)
|
||||||
{
|
{
|
||||||
Write-Host `nPlease install Skype for Business Online PowerShell Module -ForegroundColor yellow
|
Write-Host `nPlease install Skype for Business Online PowerShell Module -ForegroundColor yellow
|
||||||
Write-Host `nYou can download the Skype Online PowerShell module directly using below url: https://download.microsoft.com/download/2/0/5/2050B39B-4DA5-48E0-B768-583533B42C3B/SkypeOnlinePowerShell.Exe
|
Write-Host `nYou can download the Skype Online PowerShell module directly using below url: https://download.microsoft.com/download/2/0/5/2050B39B-4DA5-48E0-B768-583533B42C3B/SkypeOnlinePowerShell.Exe
|
||||||
Write-Host `nAfter installing module, Please close all existing PowerShell sessions. Start new PowerShell console and rerun this script.
|
Write-Host `nAfter installing module, Please close all existing PowerShell sessions. Start new PowerShell console and rerun this script.
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
Write-Host Preparing required PowerShell Modules...
|
Write-Host Preparing required PowerShell Modules...
|
||||||
Get-PSSession | Remove-PSSession
|
Get-PSSession | Remove-PSSession
|
||||||
#Authentication using MFA
|
#Authentication using MFA
|
||||||
if($MFA.IsPresent)
|
if($MFA.IsPresent)
|
||||||
{
|
{
|
||||||
Write-Host Importing Skype for Business Online PowerShell Module...
|
Write-Host Importing Skype for Business Online PowerShell Module...
|
||||||
$sfbSession = New-CsOnlineSession
|
$sfbSession = New-CsOnlineSession
|
||||||
Import-PSSession $sfbSession -AllowClobber | Out-Null
|
Import-PSSession $sfbSession -AllowClobber | Out-Null
|
||||||
Write-Host Importing Microsoft Teams PowerShell Module...
|
Write-Host Importing Microsoft Teams PowerShell Module...
|
||||||
Connect-MicrosoftTeams | Out-Null
|
Connect-MicrosoftTeams | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
#Authentication using non-MFA
|
#Authentication using non-MFA
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
||||||
if(($UserName -ne "") -and ($Password -ne ""))
|
if(($UserName -ne "") -and ($Password -ne ""))
|
||||||
{
|
{
|
||||||
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
||||||
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$Credential=Get-Credential -Credential $null
|
$Credential=Get-Credential -Credential $null
|
||||||
}
|
}
|
||||||
Write-Host Importing Skype for Business Online PowerShell Module...
|
Write-Host Importing Skype for Business Online PowerShell Module...
|
||||||
$sfbSession = New-CsOnlineSession -Credential $Credential
|
$sfbSession = New-CsOnlineSession -Credential $Credential
|
||||||
Import-PSSession $sfbSession -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
Import-PSSession $sfbSession -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
||||||
Write-Host Importing Microsoft Teams PowerShell Module...
|
Write-Host Importing Microsoft Teams PowerShell Module...
|
||||||
Connect-MicrosoftTeams -Credential $Credential | Out-Null
|
Connect-MicrosoftTeams -Credential $Credential | Out-Null
|
||||||
}
|
}
|
||||||
[boolean]$Delay=$false
|
[boolean]$Delay=$false
|
||||||
Do {
|
Do {
|
||||||
if($Action -eq "")
|
if($Action -eq "")
|
||||||
{
|
{
|
||||||
if($Delay -eq $true)
|
if($Delay -eq $true)
|
||||||
{
|
{
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
}
|
}
|
||||||
$Delay=$true
|
$Delay=$true
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-host `nPrivate Channel Management -ForegroundColor Yellow
|
Write-host `nPrivate Channel Management -ForegroundColor Yellow
|
||||||
Write-Host " 1.Allow for Organization" -ForegroundColor Cyan
|
Write-Host " 1.Allow for Organization" -ForegroundColor Cyan
|
||||||
Write-Host " 2.Disable for Organization" -ForegroundColor Cyan
|
Write-Host " 2.Disable for Organization" -ForegroundColor Cyan
|
||||||
Write-Host " 3.Allow for a User" -ForegroundColor Cyan
|
Write-Host " 3.Allow for a User" -ForegroundColor Cyan
|
||||||
Write-Host " 4.Disable for a User" -ForegroundColor Cyan
|
Write-Host " 4.Disable for a User" -ForegroundColor Cyan
|
||||||
Write-Host " 5.Allow User in bulk using CSV import" -ForegroundColor Cyan
|
Write-Host " 5.Allow User in bulk using CSV import" -ForegroundColor Cyan
|
||||||
Write-Host " 6.Disable User in bulk using CSV import" -ForegroundColor Cyan
|
Write-Host " 6.Disable User in bulk using CSV import" -ForegroundColor Cyan
|
||||||
Write-Host `nPrivate Channel Reporting -ForegroundColor Yellow
|
Write-Host `nPrivate Channel Reporting -ForegroundColor Yellow
|
||||||
Write-Host " 7.All Private Channels in Organization" -ForegroundColor Cyan
|
Write-Host " 7.All Private Channels in Organization" -ForegroundColor Cyan
|
||||||
Write-Host " 8.All Private Channels in Teams" -ForegroundColor Cyan
|
Write-Host " 8.All Private Channels in Teams" -ForegroundColor Cyan
|
||||||
Write-Host " 9.Members and Owners Report of All Private Channels" -ForegroundColor Cyan
|
Write-Host " 9.Members and Owners Report of All Private Channels" -ForegroundColor Cyan
|
||||||
Write-Host " 10.Members and Owners Report of Single Private Channel" -ForegroundColor Cyan
|
Write-Host " 10.Members and Owners Report of Single Private Channel" -ForegroundColor Cyan
|
||||||
Write-Host " 0.Exit" -ForegroundColor Cyan
|
Write-Host " 0.Exit" -ForegroundColor Cyan
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
$i = Read-Host 'Please choose the action to continue'
|
$i = Read-Host 'Please choose the action to continue'
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$i=$Action
|
$i=$Action
|
||||||
}
|
}
|
||||||
Switch ($i) {
|
Switch ($i) {
|
||||||
1 {
|
1 {
|
||||||
Set-CsTeamsChannelsPolicy -Identity Global –AllowPrivateChannelCreation $True
|
Set-CsTeamsChannelsPolicy -Identity Global –AllowPrivateChannelCreation $True
|
||||||
Write-Host Private Channel creation allowed for Organization wide -ForegroundColor Green
|
Write-Host Private Channel creation allowed for Organization wide -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
2 {
|
2 {
|
||||||
Set-CsTeamsChannelsPolicy -Identity Global –AllowPrivateChannelCreation $False
|
Set-CsTeamsChannelsPolicy -Identity Global –AllowPrivateChannelCreation $False
|
||||||
Write-Host Blocked Private Channel creation Organization wide -ForegroundColor Green
|
Write-Host Blocked Private Channel creation Organization wide -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
3 {
|
3 {
|
||||||
if((Get-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -ErrorAction silent) -eq $null)
|
if((Get-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -ErrorAction silent) -eq $null)
|
||||||
{
|
{
|
||||||
New-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -AllowPrivateChannelCreation $True | Out-Null
|
New-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -AllowPrivateChannelCreation $True | Out-Null
|
||||||
}
|
}
|
||||||
$User=Read-Host Enter User name"(UPN format)" to grant the right to create Private Channel
|
$User=Read-Host Enter User name"(UPN format)" to grant the right to create Private Channel
|
||||||
Grant-CsTeamsChannelsPolicy -PolicyName "Allow Private Channel Creation" -Identity $User
|
Grant-CsTeamsChannelsPolicy -PolicyName "Allow Private Channel Creation" -Identity $User
|
||||||
if($?)
|
if($?)
|
||||||
{
|
{
|
||||||
Write-host `nNow $User can create Private Channel -ForegroundColor Green
|
Write-host `nNow $User can create Private Channel -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
4 {
|
4 {
|
||||||
if((Get-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -ErrorAction silent) -eq $null)
|
if((Get-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -ErrorAction silent) -eq $null)
|
||||||
{
|
{
|
||||||
New-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -AllowPrivateChannelCreation $False | Out-Null
|
New-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -AllowPrivateChannelCreation $False | Out-Null
|
||||||
}
|
}
|
||||||
$User=Read-Host Enter User name"(UPN format)" to disable Private Channel creation
|
$User=Read-Host Enter User name"(UPN format)" to disable Private Channel creation
|
||||||
Grant-CsTeamsChannelsPolicy -PolicyName "Disable Private Channel Creation" -Identity $User
|
Grant-CsTeamsChannelsPolicy -PolicyName "Disable Private Channel Creation" -Identity $User
|
||||||
if($?)
|
if($?)
|
||||||
{
|
{
|
||||||
$?
|
$?
|
||||||
Write-host `nPrivate Channel creation blocked for $User -ForegroundColor green
|
Write-host `nPrivate Channel creation blocked for $User -ForegroundColor green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
5 {
|
5 {
|
||||||
if((Get-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -ErrorAction silent) -eq $null)
|
if((Get-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -ErrorAction silent) -eq $null)
|
||||||
{
|
{
|
||||||
New-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -AllowPrivateChannelCreation $True
|
New-CsTeamsChannelsPolicy -Identity "Allow Private Channel Creation" -AllowPrivateChannelCreation $True
|
||||||
}
|
}
|
||||||
Write-Host `nThe file must follow the format: Users"'" UPN separated by new line without header -ForegroundColor Magenta
|
Write-Host `nThe file must follow the format: Users"'" UPN separated by new line without header -ForegroundColor Magenta
|
||||||
$UserNamesFile=Read-Host Enter CSV/txt file path"(Eg:C:\Users\Desktop\UserNames.txt)"
|
$UserNamesFile=Read-Host Enter CSV/txt file path"(Eg:C:\Users\Desktop\UserNames.txt)"
|
||||||
$Users=@()
|
$Users=@()
|
||||||
$Users=Import-Csv -Header "UserPrincipalName" $UserNamesFile
|
$Users=Import-Csv -Header "UserPrincipalName" $UserNamesFile
|
||||||
foreach($User in $Users)
|
foreach($User in $Users)
|
||||||
{
|
{
|
||||||
Grant-CsTeamsChannelsPolicy -PolicyName "Allow Private Channel Creation" -Identity $User.UserPrincipalName
|
Grant-CsTeamsChannelsPolicy -PolicyName "Allow Private Channel Creation" -Identity $User.UserPrincipalName
|
||||||
if($?)
|
if($?)
|
||||||
{
|
{
|
||||||
Write-host Now $User.UserPrincipalName can create Private Channel -ForegroundColor Green
|
Write-host Now $User.UserPrincipalName can create Private Channel -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
6 {
|
6 {
|
||||||
if((Get-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -ErrorAction silent) -eq $null)
|
if((Get-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -ErrorAction silent) -eq $null)
|
||||||
{
|
{
|
||||||
New-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -AllowPrivateChannelCreation $False
|
New-CsTeamsChannelsPolicy -Identity "Disable Private Channel Creation" -AllowPrivateChannelCreation $False
|
||||||
}
|
}
|
||||||
Write-Host `nThe file must follow the format: Users"'" UPN separated by new line without header -ForegroundColor Magenta
|
Write-Host `nThe file must follow the format: Users"'" UPN separated by new line without header -ForegroundColor Magenta
|
||||||
$UserNamesFile=Read-Host Enter CSV/txt file path"(Eg:C:\Users\Desktop\UserNames.txt)"
|
$UserNamesFile=Read-Host Enter CSV/txt file path"(Eg:C:\Users\Desktop\UserNames.txt)"
|
||||||
$Users=@()
|
$Users=@()
|
||||||
$Users=Import-Csv -Header "UserPrincipalName" $UserNamesFile
|
$Users=Import-Csv -Header "UserPrincipalName" $UserNamesFile
|
||||||
foreach($User in $Users)
|
foreach($User in $Users)
|
||||||
{
|
{
|
||||||
Grant-CsTeamsChannelsPolicy -PolicyName "Disable Private Channel Creation" -Identity $User.UserPrincipalName
|
Grant-CsTeamsChannelsPolicy -PolicyName "Disable Private Channel Creation" -Identity $User.UserPrincipalName
|
||||||
if($?)
|
if($?)
|
||||||
{
|
{
|
||||||
Write-host Private Channel creation blocked for $User.UserPrincipalName -ForegroundColor Green
|
Write-host Private Channel creation blocked for $User.UserPrincipalName -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
7 {
|
7 {
|
||||||
$Result=""
|
$Result=""
|
||||||
$Results=@()
|
$Results=@()
|
||||||
$Path="./AllPrivateChannels_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$Path="./AllPrivateChannels_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
Write-Host Exporting Private Channels report...
|
Write-Host Exporting Private Channels report...
|
||||||
$Count=0
|
$Count=0
|
||||||
Get-Team | foreach {
|
Get-Team | foreach {
|
||||||
$TeamName=$_.DisplayName
|
$TeamName=$_.DisplayName
|
||||||
Write-Progress -Activity "`n Processed Teams count: $Count "`n" Currently Processing: $TeamName"
|
Write-Progress -Activity "`n Processed Teams count: $Count "`n" Currently Processing: $TeamName"
|
||||||
$Count++
|
$Count++
|
||||||
$GroupId=$_.GroupId
|
$GroupId=$_.GroupId
|
||||||
$PrivateChannels=(Get-TeamChannel -GroupId $GroupId -MembershipType Private).DisplayName
|
$PrivateChannels=(Get-TeamChannel -GroupId $GroupId -MembershipType Private).DisplayName
|
||||||
foreach($PrivateChannel in $PrivateChannels)
|
foreach($PrivateChannel in $PrivateChannels)
|
||||||
{
|
{
|
||||||
$Result=@{'Teams Name'=$TeamName;'Private Channel'=$PrivateChannel}
|
$Result=@{'Teams Name'=$TeamName;'Private Channel'=$PrivateChannel}
|
||||||
$Results= New-Object psobject -Property $Result
|
$Results= New-Object psobject -Property $Result
|
||||||
$Results | select 'Teams Name','Private Channel' | Export-Csv $Path -NoTypeInformation -Append
|
$Results | select 'Teams Name','Private Channel' | Export-Csv $Path -NoTypeInformation -Append
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "`n Processed Teams count: $Count "`n" Currently Processing: $TeamName" -Completed
|
Write-Progress -Activity "`n Processed Teams count: $Count "`n" Currently Processing: $TeamName" -Completed
|
||||||
if((Test-Path -Path $Path) -eq "True")
|
if((Test-Path -Path $Path) -eq "True")
|
||||||
{
|
{
|
||||||
Write-Host `nReport available in $Path -ForegroundColor Green
|
Write-Host `nReport available in $Path -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
8 {
|
8 {
|
||||||
$TeamName=Read-Host Enter Teams name "(Case Sensitive)":
|
$TeamName=Read-Host Enter Teams name "(Case Sensitive)":
|
||||||
Write-Host Exporting Private Channel report...
|
Write-Host Exporting Private Channel report...
|
||||||
$GroupId=(Get-Team -DisplayName $TeamName).GroupId
|
$GroupId=(Get-Team -DisplayName $TeamName).GroupId
|
||||||
$Path=".\Private Channels available in $TeamName$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$Path=".\Private Channels available in $TeamName$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
Get-TeamChannel -GroupId $GroupId -MembershipType Private | select DisplayName | Export-Csv $Path -NoTypeInformation
|
Get-TeamChannel -GroupId $GroupId -MembershipType Private | select DisplayName | Export-Csv $Path -NoTypeInformation
|
||||||
if((Test-Path -Path $Path) -eq "True")
|
if((Test-Path -Path $Path) -eq "True")
|
||||||
{
|
{
|
||||||
Write-Host `nReport available in $Path -ForegroundColor Green
|
Write-Host `nReport available in $Path -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
9{
|
9{
|
||||||
$Result=""
|
$Result=""
|
||||||
$Results=@()
|
$Results=@()
|
||||||
Write-Host Exporting all Private Channel"'s" Members and Owners report...
|
Write-Host Exporting all Private Channel"'s" Members and Owners report...
|
||||||
$Count=0
|
$Count=0
|
||||||
$Path="./AllPrivateChannels Members and Owners Report_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$Path="./AllPrivateChannels Members and Owners Report_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
Get-Team | foreach {
|
Get-Team | foreach {
|
||||||
$TeamName=$_.DisplayName
|
$TeamName=$_.DisplayName
|
||||||
$GroupId=$_.GroupId
|
$GroupId=$_.GroupId
|
||||||
$PrivateChannels=(Get-TeamChannel -GroupId $GroupId -MembershipType Private).DisplayName
|
$PrivateChannels=(Get-TeamChannel -GroupId $GroupId -MembershipType Private).DisplayName
|
||||||
foreach($PrivateChannel in $PrivateChannels)
|
foreach($PrivateChannel in $PrivateChannels)
|
||||||
{
|
{
|
||||||
Write-Progress -Activity "`n Processed Private Channel count: $Count "`n" Currently Processing: $PrivateChannel"
|
Write-Progress -Activity "`n Processed Private Channel count: $Count "`n" Currently Processing: $PrivateChannel"
|
||||||
$Count++
|
$Count++
|
||||||
Get-TeamChannelUser -GroupId $GroupId -DisplayName $PrivateChannel | foreach {
|
Get-TeamChannelUser -GroupId $GroupId -DisplayName $PrivateChannel | foreach {
|
||||||
$Name=$_.Name
|
$Name=$_.Name
|
||||||
$UPN=$_.User
|
$UPN=$_.User
|
||||||
$Role=$_.Role
|
$Role=$_.Role
|
||||||
$Result=@{'Teams Name'=$TeamName;'Private Channel Name'=$PrivateChannel;'UPN'=$UPN;'User Display Name'=$Name;'Role'=$Role}
|
$Result=@{'Teams Name'=$TeamName;'Private Channel Name'=$PrivateChannel;'UPN'=$UPN;'User Display Name'=$Name;'Role'=$Role}
|
||||||
$Results= New-Object psobject -Property $Result
|
$Results= New-Object psobject -Property $Result
|
||||||
$Results | select 'Teams Name','Private Channel Name',UPN,'User Display Name',Role | Export-Csv $Path -NoTypeInformation -Append
|
$Results | select 'Teams Name','Private Channel Name',UPN,'User Display Name',Role | Export-Csv $Path -NoTypeInformation -Append
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "`n Processed Private Channel count: $Count "`n" Currently Processing: $PrivateChannel" -Completed
|
Write-Progress -Activity "`n Processed Private Channel count: $Count "`n" Currently Processing: $PrivateChannel" -Completed
|
||||||
if((Test-Path -Path $Path) -eq "True")
|
if((Test-Path -Path $Path) -eq "True")
|
||||||
{
|
{
|
||||||
Write-Host `nReport available in $Path -ForegroundColor Green
|
Write-Host `nReport available in $Path -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
10 {
|
10 {
|
||||||
$Result=""
|
$Result=""
|
||||||
$Results=@()
|
$Results=@()
|
||||||
$TeamName=Read-Host Enter Teams name in which Private Channel resides "(Case sensitive)":
|
$TeamName=Read-Host Enter Teams name in which Private Channel resides "(Case sensitive)":
|
||||||
$ChannelName=Read-Host Enter Private Channel name
|
$ChannelName=Read-Host Enter Private Channel name
|
||||||
$GroupId=(Get-Team -DisplayName $TeamName).GroupId
|
$GroupId=(Get-Team -DisplayName $TeamName).GroupId
|
||||||
Write-Host Exporting $ChannelName"'s" Members and Owners report...
|
Write-Host Exporting $ChannelName"'s" Members and Owners report...
|
||||||
$Path=".\MembersOf $ChannelName$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$Path=".\MembersOf $ChannelName$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
Get-TeamChannelUser -GroupId $GroupId -DisplayName $ChannelName | foreach {
|
Get-TeamChannelUser -GroupId $GroupId -DisplayName $ChannelName | foreach {
|
||||||
$Name=$_.Name
|
$Name=$_.Name
|
||||||
$UPN=$_.User
|
$UPN=$_.User
|
||||||
$Role=$_.Role
|
$Role=$_.Role
|
||||||
$Result=@{'Teams Name'=$TeamName;'Private Channel Name'=$ChannelName;'UPN'=$UPN;'User Display Name'=$Name;'Role'=$Role}
|
$Result=@{'Teams Name'=$TeamName;'Private Channel Name'=$ChannelName;'UPN'=$UPN;'User Display Name'=$Name;'Role'=$Role}
|
||||||
$Results= New-Object psobject -Property $Result
|
$Results= New-Object psobject -Property $Result
|
||||||
$Results | select 'Teams Name','Private Channel Name',UPN,'User Display Name',Role | Export-Csv $Path -NoTypeInformation -Append
|
$Results | select 'Teams Name','Private Channel Name',UPN,'User Display Name',Role | Export-Csv $Path -NoTypeInformation -Append
|
||||||
}
|
}
|
||||||
if((Test-Path -Path $Path) -eq "True")
|
if((Test-Path -Path $Path) -eq "True")
|
||||||
{
|
{
|
||||||
Write-Host `nReport available in $Path -ForegroundColor Green
|
Write-Host `nReport available in $Path -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($Action -ne "")
|
if($Action -ne "")
|
||||||
{exit}
|
{exit}
|
||||||
}
|
}
|
||||||
While ($i -ne 0)
|
While ($i -ne 0)
|
||||||
Clear-Host
|
Clear-Host
|
||||||
|
|
||||||
216
Office 365 User Logon History Report/O365UserLoginHistory.ps1
Normal file
216
Office 365 User Logon History Report/O365UserLoginHistory.ps1
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
Param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[switch]$Success,
|
||||||
|
[switch]$Failed,
|
||||||
|
[switch]$MFA,
|
||||||
|
[Nullable[DateTime]]$StartDate,
|
||||||
|
[Nullable[DateTime]]$EndDate,
|
||||||
|
[string]$UserName,
|
||||||
|
[string]$AdminName,
|
||||||
|
[string]$Password
|
||||||
|
)
|
||||||
|
|
||||||
|
#Getting StartDate and EndDate for Audit log
|
||||||
|
if ((($StartDate -eq $null) -and ($EndDate -ne $null)) -or (($StartDate -ne $null) -and ($EndDate -eq $null)))
|
||||||
|
{
|
||||||
|
Write-Host `nPlease enter both StartDate and EndDate for Audit log collection -ForegroundColor Red
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
elseif(($StartDate -eq $null) -and ($EndDate -eq $null))
|
||||||
|
{
|
||||||
|
$StartDate=(((Get-Date).AddDays(-90))).Date
|
||||||
|
$EndDate=Get-Date
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$StartDate=[DateTime]$StartDate
|
||||||
|
$EndDate=[DateTime]$EndDate
|
||||||
|
if($StartDate -lt ((Get-Date).AddDays(-90)))
|
||||||
|
{
|
||||||
|
Write-Host `nAudit log can be retrieved only for past 90 days. Please select a date after (Get-Date).AddDays(-90) -ForegroundColor Red
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
if($EndDate -lt ($StartDate))
|
||||||
|
{
|
||||||
|
Write-Host `nEnd time should be later than start time -ForegroundColor Red
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#Authentication using MFA
|
||||||
|
if($MFA.IsPresent)
|
||||||
|
{
|
||||||
|
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
||||||
|
If ($MFAExchangeModule -eq $null)
|
||||||
|
{
|
||||||
|
Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow
|
||||||
|
Write-Host You can manually install module using below blog : `nhttps://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/ `nOR you can install module directly by entering "Y"`n
|
||||||
|
$Confirm= Read-Host `nAre you sure you want to install module directly? [Y] Yes [N] No
|
||||||
|
if($Confirm -match "[Y]")
|
||||||
|
{
|
||||||
|
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
$Confirmation= Read-Host Have you installed Exchange Online MFA Module? [Y] Yes [N] No
|
||||||
|
if($Confirmation -match "[yY]")
|
||||||
|
{
|
||||||
|
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
||||||
|
If ($MFAExchangeModule -eq $null)
|
||||||
|
{
|
||||||
|
Write-Host Exchange Online MFA module is not available -ForegroundColor red
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host Exchange Online PowerShell Module is required
|
||||||
|
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Importing Exchange MFA Module
|
||||||
|
. "$MFAExchangeModule"
|
||||||
|
Write-Host Enter credential in prompt to connect to Exchange Online
|
||||||
|
Connect-EXOPSSession -WarningAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
#Authentication using non-MFA
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
||||||
|
if(($AdminName -ne "") -and ($Password -ne ""))
|
||||||
|
{
|
||||||
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
||||||
|
$Credential = New-Object System.Management.Automation.PSCredential $AdminName,$SecuredPassword
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$Credential=Get-Credential -Credential $null
|
||||||
|
}
|
||||||
|
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue
|
||||||
|
Import-PSSession $Session -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$OutputCSV=".\AuditLog_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
|
$IntervalTimeInMinutes=1440 #$IntervalTimeInMinutes=Read-Host Enter interval time period '(in minutes)'
|
||||||
|
$CurrentStart=$StartDate
|
||||||
|
$CurrentEnd=$CurrentStart.AddMinutes($IntervalTimeInMinutes)
|
||||||
|
|
||||||
|
#Filter for successful login attempts
|
||||||
|
if($success.IsPresent)
|
||||||
|
{
|
||||||
|
$Operation="UserLoggedIn,TeamsSessionStarted,MailboxLogin"
|
||||||
|
}
|
||||||
|
#Filter for successful login attempts
|
||||||
|
elseif($Failed.IsPresent)
|
||||||
|
{
|
||||||
|
$Operation="UserLoginFailed"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$Operation="UserLoggedIn,UserLoginFailed,TeamsSessionStarted,MailboxLogin"
|
||||||
|
}
|
||||||
|
|
||||||
|
#Check whether CurrentEnd exceeds EndDate(checks for 1st iteration)
|
||||||
|
if($CurrentEnd -gt $EndDate)
|
||||||
|
{
|
||||||
|
$CurrentEnd=$EndDate
|
||||||
|
}
|
||||||
|
|
||||||
|
$AggregateResults = 0
|
||||||
|
$CurrentResult= @()
|
||||||
|
$CurrentResultCount=0
|
||||||
|
Write-Host `nRetrieving audit log from $StartDate to $EndDate... -ForegroundColor Yellow
|
||||||
|
|
||||||
|
while($true)
|
||||||
|
{
|
||||||
|
#Write-Host Retrieving audit log between StartDate $CurrentStart to EndDate $CurrentEnd ******* IntervalTime $IntervalTimeInMinutes minutes
|
||||||
|
if($CurrentStart -eq $CurrentEnd)
|
||||||
|
{
|
||||||
|
Write-Host Start and end time are same.Please enter different time range -ForegroundColor Red
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
|
||||||
|
#Getting audit log for specific user(s) for a given time range
|
||||||
|
if($UserName -ne "")
|
||||||
|
{
|
||||||
|
$Results=Search-UnifiedAuditLog -UserIds $UserName -StartDate $CurrentStart -EndDate $CurrentEnd -operations $Operation -SessionId s -SessionCommand ReturnLargeSet -ResultSize 5000
|
||||||
|
}
|
||||||
|
|
||||||
|
#Getting audit log for all users for a given time range
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$Results=Search-UnifiedAuditLog -StartDate $CurrentStart -EndDate $CurrentEnd -Operations $Operation -SessionId s -SessionCommand ReturnLargeSet -ResultSize 5000
|
||||||
|
}
|
||||||
|
#$Results.count
|
||||||
|
$AllAuditData=@()
|
||||||
|
$AllAudits=
|
||||||
|
foreach($Result in $Results)
|
||||||
|
{
|
||||||
|
$AuditData=$Result.auditdata | ConvertFrom-Json
|
||||||
|
$AuditData.CreationTime=(Get-Date($AuditData.CreationTime)).ToLocalTime()
|
||||||
|
$AllAudits=@{'Login Time'=$AuditData.CreationTime;'User Name'=$AuditData.UserId;'IP Address'=$AuditData.ClientIP;'Operation'=$AuditData.Operation;'Result Status'=$AuditData.ResultStatus;'Workload'=$AuditData.Workload}
|
||||||
|
$AllAuditData= New-Object PSObject -Property $AllAudits
|
||||||
|
$AllAuditData | Sort 'Login Time','User Name' | select 'Login Time','User Name','IP Address',Operation,'Result Status',Workload | Export-Csv $OutputCSV -NoTypeInformation -Append
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "`n Retrieving audit log from $StartDate to $EndDate.."`n" Processed audit record count: $AggregateResults"
|
||||||
|
#$CurrentResult += $Results
|
||||||
|
$currentResultCount=$CurrentResultCount+($Results.count)
|
||||||
|
$AggregateResults +=$Results.count
|
||||||
|
if(($CurrentResultCount -eq 50000) -or ($Results.count -lt 5000))
|
||||||
|
{
|
||||||
|
if($CurrentResultCount -eq 50000)
|
||||||
|
{
|
||||||
|
Write-Host Retrieved max record for the current range.Proceeding further may cause data loss or rerun the script with reduced time interval. -ForegroundColor Red
|
||||||
|
$Confirm=Read-Host `nAre you sure you want to continue? [Y] Yes [N] No
|
||||||
|
if($Confirm -notmatch "[Y]")
|
||||||
|
{
|
||||||
|
Write-Host Please rerun the script with reduced time interval -ForegroundColor Red
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host Proceeding audit log collection with data loss
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#Check for last iteration
|
||||||
|
if(($CurrentEnd -eq $EndDate))
|
||||||
|
{
|
||||||
|
break
|
||||||
|
}
|
||||||
|
[DateTime]$CurrentStart=$CurrentEnd
|
||||||
|
#Break loop if start date exceeds current date(There will be no data)
|
||||||
|
if($CurrentStart -gt (Get-Date))
|
||||||
|
{
|
||||||
|
break
|
||||||
|
}
|
||||||
|
[DateTime]$CurrentEnd=$CurrentStart.AddMinutes($IntervalTimeInMinutes)
|
||||||
|
if($CurrentEnd -gt $EndDate)
|
||||||
|
{
|
||||||
|
$CurrentEnd=$EndDate
|
||||||
|
}
|
||||||
|
|
||||||
|
$CurrentResultCount=0
|
||||||
|
$CurrentResult = @()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
If($AggregateResults -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host No records found
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((Test-Path -Path $OutputCSV) -eq "True")
|
||||||
|
{
|
||||||
|
Write-Host `nThe Output file availble in $OutputCSV -ForegroundColor Green
|
||||||
|
}
|
||||||
|
Write-Host `nThe output file contains $AggregateResults audit records
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user