SlideShare a Scribd company logo
1 of 1
<#Import in modules, if statement for PSSnapin so that it doesn't throw
an error if it is already loaded.#>
Import-Module ActiveDirectory
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin -
ErrorAction SilentlyContinue) -eq $null )
{
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
}
<#Clear variables so they are not retaining any old values#>
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0
$errorLogPath = "c:scriptslogsSIDUsers.txt"
$adminUser = whoami
$mailboxes = Get-Mailbox -ResultSize unlimited | Where
{ $_.linkedMasterAccount -like "S-*" }
foreach ($mailbox in $mailboxes){
$fileCreationTime = Get-Date -UFormat "%Y%m%d%H%M%S"
$displayName = $mailbox.DisplayName
$pstFolderPath = Join-Path "SanitizedServerNameexchangePST"
$fileCreationTime$displayName.PST
$txtFolderPath = Join-Path "SanitizedServerNameexchangePST"
$fileCreationTime$displayName.txt
try {
Add-MailboxPermission -Identity $mailbox -User $adminUser -
AccessRights FullAccess -ErrorAction Stop -Verbose -Confirm:$false}
catch {
Write-Warning "Permission add problem, logging error to
$errorLogPath!"
Write-Warning $error[0]
$error[0] | Out-File $errorLogPath -Append}
try{
Export-Mailbox -Identity $mailbox -PSTFolderPath $pstFolderPath -
ErrorAction Stop -Verbose -Confirm:$false}
catch{
Write-Warning "Export problem!"
Write-Warning $error[0]
$error[0] | Out-File $errorLogPath -Append}
try {
Get-Mailbox -Identity $mailbox | FL | Out-File $txtFolderPath -
ErrorAction Stop -Verbose -Confirm:$false}
catch {
Write-Warning "Problem writing to txt"
Write-Warning $error[0]
$error[0] | Out-File $errorLogPath -Append}
try{
Write-Verbose "!!!!!!!!!!!!!!!!!!"
Remove-Mailbox -Identity $exUserCorpMatch[$c] -Permanent $true -
ErrorAction Stop -Verbose -Confirm:$false}
catch {
Write-Warning $error[0]
$error[0] | Out-File $errorLogPath -Append}
}

More Related Content

What's hot

Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Natasha Murashev
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementAdrian Cardenas
 
Higher-Order Components — Ilya Gelman
Higher-Order Components — Ilya GelmanHigher-Order Components — Ilya Gelman
Higher-Order Components — Ilya Gelman500Tech
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practicesClickky
 
No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETFilip Ekberg
 
Powershell function
Powershell functionPowershell function
Powershell functionLearningTech
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programmingFilip Ekberg
 
Redux training
Redux trainingRedux training
Redux trainingdasersoft
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxCommit University
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max PetruckMaksym Petruk
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced RoutingAlexe Bogdan
 
Practical Protocols with Associated Types
Practical Protocols with Associated TypesPractical Protocols with Associated Types
Practical Protocols with Associated TypesNatasha Murashev
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0Eyal Vardi
 

What's hot (20)

Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
 
Higher-Order Components — Ilya Gelman
Higher-Order Components — Ilya GelmanHigher-Order Components — Ilya Gelman
Higher-Order Components — Ilya Gelman
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NET
 
Powershell function
Powershell functionPowershell function
Powershell function
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programming
 
Redux training
Redux trainingRedux training
Redux training
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
Rails3 way
Rails3 wayRails3 way
Rails3 way
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
Clojure functions examples
Clojure functions examplesClojure functions examples
Clojure functions examples
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Practical Protocols with Associated Types
Practical Protocols with Associated TypesPractical Protocols with Associated Types
Practical Protocols with Associated Types
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 

Similar to getSIDUsers

exportDisabledUsersRemoveMailbox
exportDisabledUsersRemoveMailboxexportDisabledUsersRemoveMailbox
exportDisabledUsersRemoveMailboxDaniel Gilhousen
 
Large scale machine learning projects with R Suite
Large scale machine learning projects with R SuiteLarge scale machine learning projects with R Suite
Large scale machine learning projects with R SuiteWLOG Solutions
 
Large scale machine learning projects with r suite
Large scale machine learning projects with r suiteLarge scale machine learning projects with r suite
Large scale machine learning projects with r suiteWit Jakuczun
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developersDennis Vroegop
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingErick Hitter
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkara JUG
 
Intro to PAS REST API
Intro to PAS REST APIIntro to PAS REST API
Intro to PAS REST APIJoe Garcia
 
Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015Oleg Chorny
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershellMatt Wrock
 
Magento 2 | Declarative schema
Magento 2 | Declarative schemaMagento 2 | Declarative schema
Magento 2 | Declarative schemaKiel Pykett
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changerSandro Paganotti
 

Similar to getSIDUsers (20)

MassChangeCORPEmail
MassChangeCORPEmailMassChangeCORPEmail
MassChangeCORPEmail
 
MassMigrateUsersOU
MassMigrateUsersOUMassMigrateUsersOU
MassMigrateUsersOU
 
exportDisabledUsersRemoveMailbox
exportDisabledUsersRemoveMailboxexportDisabledUsersRemoveMailbox
exportDisabledUsersRemoveMailbox
 
termUserGroups
termUserGroupstermUserGroups
termUserGroups
 
Large scale machine learning projects with R Suite
Large scale machine learning projects with R SuiteLarge scale machine learning projects with R Suite
Large scale machine learning projects with R Suite
 
Large scale machine learning projects with r suite
Large scale machine learning projects with r suiteLarge scale machine learning projects with r suite
Large scale machine learning projects with r suite
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Java day9n
Java day9nJava day9n
Java day9n
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developers
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Intro to PAS REST API
Intro to PAS REST APIIntro to PAS REST API
Intro to PAS REST API
 
Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
 
Magento 2 | Declarative schema
Magento 2 | Declarative schemaMagento 2 | Declarative schema
Magento 2 | Declarative schema
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 

getSIDUsers

  • 1. <#Import in modules, if statement for PSSnapin so that it doesn't throw an error if it is already loaded.#> Import-Module ActiveDirectory if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin - ErrorAction SilentlyContinue) -eq $null ) { add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin } <#Clear variables so they are not retaining any old values#> Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0 $errorLogPath = "c:scriptslogsSIDUsers.txt" $adminUser = whoami $mailboxes = Get-Mailbox -ResultSize unlimited | Where { $_.linkedMasterAccount -like "S-*" } foreach ($mailbox in $mailboxes){ $fileCreationTime = Get-Date -UFormat "%Y%m%d%H%M%S" $displayName = $mailbox.DisplayName $pstFolderPath = Join-Path "SanitizedServerNameexchangePST" $fileCreationTime$displayName.PST $txtFolderPath = Join-Path "SanitizedServerNameexchangePST" $fileCreationTime$displayName.txt try { Add-MailboxPermission -Identity $mailbox -User $adminUser - AccessRights FullAccess -ErrorAction Stop -Verbose -Confirm:$false} catch { Write-Warning "Permission add problem, logging error to $errorLogPath!" Write-Warning $error[0] $error[0] | Out-File $errorLogPath -Append} try{ Export-Mailbox -Identity $mailbox -PSTFolderPath $pstFolderPath - ErrorAction Stop -Verbose -Confirm:$false} catch{ Write-Warning "Export problem!" Write-Warning $error[0] $error[0] | Out-File $errorLogPath -Append} try { Get-Mailbox -Identity $mailbox | FL | Out-File $txtFolderPath - ErrorAction Stop -Verbose -Confirm:$false} catch { Write-Warning "Problem writing to txt" Write-Warning $error[0] $error[0] | Out-File $errorLogPath -Append} try{ Write-Verbose "!!!!!!!!!!!!!!!!!!" Remove-Mailbox -Identity $exUserCorpMatch[$c] -Permanent $true - ErrorAction Stop -Verbose -Confirm:$false} catch { Write-Warning $error[0] $error[0] | Out-File $errorLogPath -Append} }