Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Cd 'C:\Users\%UserName%\Documents\WindowsPowerShell'
- #To Begin, CD to desktop, dot-source PS Bible v5.3.ps1, then type SelectCustomer and press enter.
- #region
- #Script Functions
- Function SelectCustomer {
- cls
- echo ""
- Write-Host "Please select a customer and press enter." -ForegroundColor Cyan
- echo ""
- echo " 1. Customer 1 01234 567 891"
- echo " 2. Customer 2 09843 123 123"
- echo ""
- Write-Host " -Or select M to skip signing in and head straight for the main menu-" -ForegroundColor Magenta
- "`n"
- $customer = Read-Host "Enter the number relating to the customer"
- if ($customer -eq 1){$loginwith = 'admin@company1.onmicrosoft.com'}
- if ($customer -eq 2){$loginwith = 'admin@company2.onmicrosoft.com'}
- if ($customer -eq "M"){Main-Menu}
- if ($customer -eq "m"){Main-Menu}
- if ($customer -gt "21"){Write-Host -ForegroundColor Red "Invalid Selection, please try again!" | SelectCustomer}
- $O365Cred = Get-Credential -UserName $loginwith -Message "Enter your Office 365 Admin Password for $loginwith"
- $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange `
- -ConnectionUri https://ps.outlook.com/powershell `
- -Credential $O365Cred -Authentication Basic `
- -AllowRedirection `
- Connect-AzureAD -Credential $O365Cred
- Connect-MsolService -Credential $O365Cred
- Import-Module MSOnline
- Import-PSSession $O365Session
- Get-MsolDomain
- "" # Blank Line
- "Welcome " + $env:UserName + "!"
- Write-Host "`n"
- "The the time is currently " + "{0:HH}:{0:mm} GMT" -f (Get-Date)
- Main-Menu
- "`n" # Blank Line
- }
- Function Clear-UserVariables {
- $x=powershell -nologo -command "gv|out-string"
- $y=($x|select -skip 15) -split "\s+",2
- $varnames = $(for ($i=0;$i -lt $y.length; $i+=2) { $y[$i]})
- rv i,x,y
- gv | % {if ($varnames -notcontains $_.name) {rv $_.name -EA 0}}
- }
- Function Disconnect-ExchangeOnline {
- ;
- Get-PSSession | Where-Object {$_.ConfigurationName -eq “Microsoft.Exchange”} |
- Remove-PSSession
- }
- Function Wait-KeyInput {
- Read-Host "Press Enter to return to the Main Menu"
- Main-Menu
- }
- Function Exit-Menu {$ExitMenu = read-host "Are you sure you want to exit? (y/n)"
- if ($ExitMenu -eq "y"){exit}
- if ($ExitMenu -eq "n"){Main-Menu}
- else {write-host -foregroundcolor red "Invalid Selection"
- areyousure}
- }
- Function Get-Time {
- Write-Host "`n"
- "The time is currently " + "{0:HH}:{0:mm} GMT" -f (Get-Date)
- }
- Function MBUsage-Menu { cls
- Write-Host "Would you like to find information on a particular user or all mailboxes?"
- ""
- "--Get Mailbox Statistics--"
- "---------------------------------------------------------"
- echo " 1. Single User"
- echo " 2. All Mailboxes"
- "---------------------------------------------------------"
- #echo "" #blankline
- echo "--Press R to return to the Main Menu--"
- ""
- $answer = Read-Host "Please make a selection"
- if ($answer -eq 1){Get-SingleMBStat}
- if ($answer -eq 2){Get-AllMBStat}
- if ($answer -eq "R"){Main-Menu}
- }
- #endregion
- #region
- #Office 365 Exchange
- Function Convert-MailboxRemoveLicense {
- $emailaddress = Read-Host -Prompt 'Please enter the username'
- "`n"
- $mbname = $emailaddress
- $sharedanswer = Read-Host -Prompt 'Would you like to convert this user to a shared mailbox?(Yes/No)'
- If($sharedanswer -eq "Yes"){Set-Mailbox -Identity $mbname -Type Shared -Force}
- #This might fail if the mailbox name doesn't match the .FirstName principal from earlier, work on a solution to get mailbox name from UPN
- "`n"
- $assignedlicenses = Get-MsolUser -UserPrincipalName $emailaddress
- $assignedlicenses.Licenses.AccountSkuId
- "`n"
- $licensetoremove = Read-Host -Prompt "Please type the license you wish to remove"
- Set-MsolUserLicense -UserPrincipalName $emailaddress -RemoveLicenses $licensetoremove
- "`n"
- Write-Host "$licensetoremove has been revoked from $emailaddress" `
- -BackgroundColor Green -ForegroundColor White
- "`n"
- $mbtype = Get-Mailbox -Identity $mbname | Select-Object RecipientTypeDetails
- Write-Host "Mailbox: $emailaddress has been converted."
- $mbtype
- Main-Menu
- }
- Function Get-AllMBStat {
- Write-Host "Please wait, this may take some time..." -ForegroundColor Green
- Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, ItemCount, TotalItemSize, ProhibitSendQuota |
- Out-GridView
- }
- Function Get-SingleMBStat {
- $mailboxuser = Read-Host "Please enter the mailbox to check"
- Get-Mailbox $mailboxuser | Get-MailboxStatistics | Select-Object DisplayName, `
- ItemCount, TotalItemSize, ProhibitSendQuota | Format-Table –autosize
- }
- Function Get-MBUsageByLicense {
- $var1 = Get-MsolAccountSku
- Write-Host $var1
- $var1.AccountSkuID, $var1.ActiveUnits, $var1.ConsumedUnits
- $licensetype = Read-Host "Enter company name and license type, i.e. Contoso:O365_BUSINESS_PREMIUM"
- $licensedUsers = Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" }
- $enterpriseUsers = $licensedUsers | Where-Object { $_.Licenses.AccountSkuId -eq "$licensetype" }
- $mbStats = @()
- foreach ($user in $enterpriseUsers) {
- $mbStats += get-mailbox $user.signinname | get-mailboxstatistics |
- select-object displayname, itemcount, totalitemsize, ProhibitSendQuota, mailboxguid
- }
- $mbStats | select-object displayname, itemcount, totalitemsize, prohibitsendquota |
- Sort-Object TotalItemSize | format-table -AutoSize
- }
- Function Forward-Mail {
- $forwardfrom = Read-Host "Please enter the email address to forward from"
- $forwardto = Read-Host "Please enter the email address to forward to"
- $deliverandforward = Read-Host "Do you wish to deliver to initial mailbox and forward? (True/false)"
- If ($deliverandforward -eq "True"){[bool]$deliverandforward = 1}
- Else{[bool] $deliverandforward = 0}
- Set-Mailbox -Identity $forwardfrom `
- -ForwardingSmtpAddress $forwardto `
- -DeliverToMailboxAndForward $deliverandforward
- Write-Host $forwardfrom {Get-Mailbox -Identity $forwardfrom | FL ForwardingSMTPAddress}
- }
- Function Set-Automap {
- $Mapmailbox = Read-Host "Please enter the mailbox you would like to automap"
- $Mapto = Read-Host "Please enter the user you would like the mailbox mapped to"
- Add-MailboxPermission $Mapmailbox -User $Mapto -AccessRights FullAccess -AutoMapping $true
- Write-Host "$Mapmailbox has been automapped to $Mapto with FullAccess Permissions."
- }
- Function Add-Alias {
- $SelectMailbox = Read-Host "Enter the primary mailbox"
- Get-Mailbox $SelectMailbox | Select -ExpandProperty Emailaddresses Alias
- $AliasToAdd = Read-Host "Please type in the alias you would like to add"
- Set-Mailbox $SelectMailbox -EmailAddresses @{Add=$AliasToAdd}
- Write-Host $AliasToAdd has been added as an alias to $SelectMailbox. -ForegroundColor Green
- }
- Function Remove-Alias {
- $SelectMailbox = Read-Host "Enter the primary mailbox"
- Write-Host "Please be aware the, addresses with SMTP in capitals are PRIMARY" -ForegroundColor Red
- Get-Mailbox $SelectMailbox | Select -ExpandProperty Emailaddresses Alias
- $AliasToRemove = Read-Host "Please enter the alias you would like to remove"
- Set-Mailbox $SelectMailbox -EmailAddresses @{Remove=$aliastoremove}
- Write-Host $AliasToRemove has been removed as an alias from $SelectMailbox. -ForegroundColor Green
- }
- Function Create-DistributionGroup { #Under construction#
- $distgroupname = Read-Host "Please enter a name for the new Distribution Group"
- $primarysmtp = Read-Host "Please choose a primary email address for the group"
- $externalsend = Read-Host "Can this group receive mail from external addresses (True/False)?"
- If ($externalsend -eq "True"){[bool]$externalsend = 1}
- Else{[bool] $externalsend = 0}
- New-DistributionGroup -Name $distgroupname -DisplayName $distgroupname `
- -PrimarySmtpAddress $primarysmtp `
- -RequireSenderAuthenticationEnabled $externalsend
- Write-Host "Your new distribution group, $distgroupname has been created, now let's add some members" `
- -ForegroundColor Green
- $members = Read-Host "Please enter the members separated by commas and contained in double quote marks"
- Add-DistributionGroupMember -Identity $primarysmtp -Member $members
- }
- function Get-MemberDistGroup {
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory=$true)]
- [Alias('Email')]
- [string]$UserName
- )
- $user = Get-User $username; $groups = Get-Group | Where-Object {$_.Members -contains $user}
- Write-Host "If no results appear. try invoking cmdlet manually with Get-MemberDistGroup" -ForegroundColor Cyan -NoNewline
- foreach ($group in $groups) {
- $props = @{'Name' = $group.Name;
- 'PrimaryEmail' = $group.WindowsEmailAddress}
- $obj = New-Object -TypeName PSObject -Property $props
- Write-Output $obj
- }
- }
- #endregion
- #region
- #Office 365 Administration
- Function New-O365User {
- $firstname = Read-Host -Prompt 'Enter the first name'
- $lastname = Read-Host -Prompt 'Enter the last name'
- $primaryemail = Read-Host -Prompt 'Enter the desired email address, i.e. Firstname.lastname@company.com'
- $displayname = -join("$firstname", " ", "$lastname")
- $usagelocation = Read-Host -Prompt 'Enter the usage location (GB/US/ETC.)'
- $var1 = Get-MsolAccountSku
- Write-Host $var1
- $var1.AccountSkuID, $var1.ActiveUnits, $var1.ConsumedUnits
- $license = Read-Host -Prompt 'Enter license type'
- $password = Read-Host -Prompt 'Choose a password'
- $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
- IF($answer -eq "True"){[bool]$forcechangepassword = 1} `
- Else{[bool]$forcechangepassword = 0}
- $answer2 = Read-Host -Prompt 'Do you wish for this password to expire every 90 days? (True/False)'
- If($answer2 -eq "True"){[bool]$passwordexpiry = 1} `
- Else{[bool]$passwordexpiry = 0}
- New-MsolUser -FirstName $firstname `
- -LastName $lastname `
- -DisplayName $displayname `
- -UserPrincipalName $primaryemail `
- -UsageLocation $usagelocation `
- -LicenseAssignment $license `
- -Password $password `
- -ForceChangePassword $forcechangepassword `
- -PasswordNeverExpires $passwordexpiry
- Write-Host –NoNewLine “A new user has been created: Username: $userprincipalname, Password: $password” `
- -BackgroundColor “Green” -ForegroundColor “Black”
- Clear-UserVariables
- }
- Function New-UsersBulk {
- ""
- Write-Host -ForegroundColor Green "- Create a CSV with the following columns:"
- Write-Host -ForegroundColor Green " UserPrincipalName, FirstName, LastName, DisplayName"
- Write-Host -ForegroundColor Green "- Save the CSV as, C:\IMPORTUSERS.CSV"
- Get-MsolDomain | Format-Table -AutoSize
- Write-Host "Check that the domain used in CSV matches available domains"
- $continue = Read-Host "Ready to proceed? (Y/N)"
- if ($continue -eq "Y") {
- $users = Import-Csv C:\ImportUsers.csv
- Write-Host -ForegroundColor Magenta "Reading CSV and Importing Users"
- Write-Host -ForegroundColor Magenta "Creating New Users... Please wait,"
- $users | ForEach-Object {
- New-MsolUser -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName `
- -UserPrincipalName $_.UserPrincipalName}
- }
- elseif ($continue -eq "N") {Main-Menu}
- else {Write-Host -ForegroundColor Red "Invalid Input detected" | New-UsersBulk}
- }
- Function Delete-User { #needs work
- $usertodelete = Read-Host -Prompt 'Please enter the user email address'
- $permdelete = Read-Host -Prompt 'Would you like to permanently delete the user? Yes/No'
- If($answer -eq "Yes"){[bool]$permdelete = 1} `
- Else{[bool]$permdelete = 0}
- Remove-MsolUser -UserPrincipalName $usertodelete
- #-RemoveFromRecycleBin $permdelete
- Write-Host –NoNewLine “$usertodelete has been deleted.” `
- -BackgroundColor “Green” -ForegroundColor “Black”
- }
- Function Reset-O365Password {
- #Start Menu
- $usertoreset = Read-Host -Prompt "Please enter the username required for password reset"
- $newpassword = Read-Host -Prompt "Please enter a new password or leave blank for a random password"
- $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
- IF($answer -eq "True"){[bool]$forcechangepassword = 1} `
- Else{[bool]$forcechangepassword = 0}
- Set-MsolUserPassword -UserPrincipalName $usertoreset `
- -NewPassword $newpassword `
- -ForceChangePassword $forcechangepassword `
- Write-Host "Password for user: $usertoreset has been set to $newpassword successfully" -BackgroundColor Green -ForegroundColor White
- }
- Function Get-O365Users {
- Get-Mailbox | Select-Object DisplayName, UserPrincipalName | Sort-Object DisplayName | Format-Table –autosize
- }
- Function Remove-License { #under development
- $emailaddress = Read-Host -Prompt 'Please enter the username'
- Write-Host "`n"
- Write-Host "Currently assigned licenses:" -BackgroundColor "Green" -ForegroundColor Black
- Get-MsolUser -UserPrincipalName $emailaddress | Format-List Licenses
- $licensename = Read-Host -Prompt 'Please enter the license name you wish to remove'
- Write-Host "`n"
- Set-MsolUserLicense -UserPrincipalName $emailaddress `
- -RemoveLicenses $licensename
- Write-Host –NoNewLine “$licensename has been removed from the user $emailaddress” `
- -BackgroundColor “Green” -ForegroundColor “Black”
- Write-Host "`n"
- $deleteanswer = Read-Host -Prompt 'Would you like to delete this user?(Yes/No)'
- If($deleteanswer -eq "Yes"){[bool]$deleteanswer = 1}
- Else{[bool]$deleteanswer = 0}
- $sharedanswer = Read-Host -Prompt 'Would you like to convert this user to a shared mailbox?(Yes/No)'
- If($sharedanswer -eq "Yes"){Set-Mailbox -Identity $emailaddress -Type Shared -Force}
- Get-MsolUser -UserPrincipalName $emailaddress
- Get-Mailbox -Identity $emailaddress | Format-List RecipientTypeDetails
- }
- Function License-AllUsers { foreach ($o in (Get-MsolUser -UnlicensedUsersOnly)){Set-MsolUser -
- UserPrincipalName $o.UserPrincipalName -UsageLocation GB ; SetMsolUserLicense
- -UserPrincipalName $o.UserPrincipalName -AddLicenses
- (Get-MsolAccountSku).AccountSkuId}
- }
- Function Get-O365Licenses {
- $LogFile = "C:\users\JamieHutchinson\Desktop\O365_Licenses.csv"
- write-host "Connecting to Office 365..."
- $licensetype = Get-MsolAccountSku | Where {$_.ConsumedUnits -ge 1}
- foreach ($license in $licensetype) {
- $headerstring = "DisplayName,UserPrincipalName,AccountSku"
- foreach ($row in $($license.ServiceStatus)) {
- $headerstring = ($headerstring + "," + $row.ServicePlan.servicename) }
- Out-File -FilePath $LogFile -InputObject $headerstring -Encoding UTF8 -append
- write-host ("Gathering users with the following subscription: " + $license.accountskuid)
- $users = Get-MsolUser -all | where {$_.isLicensed -eq "True" -and $_.licenses.accountskuid -contains $license.accountskuid}
- foreach ($user in $users) {
- write-host ("Processing " + $user.displayname)
- $thislicense = $user.licenses | Where-Object {$_.accountskuid -eq $license.accountskuid}
- $datastring = ($user.displayname + "," + $user.userprincipalname + "," + $license.SkuPartNumber)
- foreach ($row in $($thislicense.servicestatus)) {
- $datastring = ($datastring + "," + $($row.provisioningstatus))}
- Out-File -FilePath $LogFile -InputObject $datastring -Encoding UTF8 -append}
- Out-File -FilePath $LogFile -InputObject " " -Encoding UTF8 -append}
- write-host ("Script Completed. Results available in " + $psdir + $LogFile) -ForegroundColor Green
- }
- Function Get-UserInfo {
- $usernameforinfo = Read-Host "Enter the username to retrieve information"
- Get-MsolUser -UserPrincipalName $usernameforinfo | Format-List *
- }
- #endregion
- #region
- #Security and Compliance
- Function Enable-LitigationHold {
- $mailboxforhold = Read-Host "Please enter the mailbox name"
- $holdduration = Read-Host "Please enter the duration of hold (days)"
- $confirmhold = Read-Host "Please confirm you would like to place a litagation hold of $holdduration days on mailbox $mailboxforhold"
- If ($confirmhold -eq "Yes"){Confirm-Hold}
- Else {Write-Host -ForegroundColor Red "Invalid Selection"}
- }
- function Confirm-Hold {
- Set-Mailbox -Identity $mailboxforhold -LitigationHoldEnabled $true -LitigationHoldDuration $holdduration
- Write-Host "Mailbox $mailboxforhold is now enabled for Litigation Hold for $holdduration"
- Wait-KeyInput
- Main-Menu
- }
- #endregion
- #region
- #Miscellaneous Functions
- Function Generate-Password {
- Write-Host "Choose two words that you will remember using capital letters at the beginning of both"
- Write-Host "a password will be generated with your memorable words." -NoNewline
- $wordonesecure = Read-Host "Please type the first word in your password" -AsSecureString
- $wordtwosecure = Read-Host "Please type the second word in your password" -AsSecureString
- $wordthreesecure = Read-Host "Please type the third word in your password" -AsSecureString
- $wordonedecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordonesecure))
- $wordtwodecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordtwosecure))
- $wordthreedecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordthreesecure))
- $securestring = New-SWRandomPassword
- $securepassword = -join("$wordonedecrypted", "$wordtwodecrypted", "$wordthreedecrypted", "$securestring")
- ""
- Write-Host "Your new password has been generated:"
- Write-Host "$securepassword" -ForegroundColor Green
- }
- Function Number-Wizard {
- Clear-Host
- #Initialize replay variable so that the game plays at least once
- $replay = 1
- ## Main game loop here that runs until user decides to quit.
- While($replay -ne 0) {
- #Initializing pre-game variables
- $secretNumber = Get-Random -Minimum 1 -Maximum 100
- $closeHigh = $secretNumber + 10
- $closeLow = $secretNumber - 10
- $guesses = @()
- $message = ""
- $quit = 0
- #Sub game loop that makes up one time through the game
- While($quit -ne 1){
- $guess = ''
- Clear-Host
- Write-Host -NoNewline "`t`t`tHenlo $env:UserName, welcome to my guessing game!"
- if ($guesses.Count -ne 0){
- Write-Host "You have guessed" $guesses.Count "time(s)"
- Write-Host "Your past guesses were:"$guesses
- }
- Write-Host "`n" $message "`n"
- #Take user input. Currently very unsanitary and unexpected input could result in unexpected behavior
- While($guess -eq ''){
- $guess = Read-Host "Please guess a number between 1 and 100 (or type q to exit) and press enter"
- if ($guess -eq "q"){
- $quit = 1
- $replay = 0
- }else{
- $guessint = [int]$guess
- }
- }
- #Add the guess from this cycle to the list of past guesses
- $guesses = $guesses + $guessint
- #Checks the user input against the secret and lets them know if they've won and gives them a way out of the replay loop
- if($guessint -eq $secretNumber) {
- $quit = 1
- $playagain = ''
- While(($playagain -ne "y") -and ($playagain -ne "n")){
- Clear-Host
- Write-Host "`n`t`tYou Win!!!"
- Write-Host "You won the game after" $guesses.Count "guesses!"
- Write-Host "`nDo you want to try again?"
- $playagain = Read-Host "Please type Y for yes or N for no and press enter"
- }
- if ($playagain -eq "y"){
- break
- } else {
- $replay = 0
- }
- # Proximity handling to build feedback for the user
- } elseif(($guessint -le $closeHigh) -and ($guessint -gt $closeLow)) {
- $message = "You're getting close! Just a bit too "
- } else {
- $message = "Way too "
- }
- if($guessint -lt $secretNumber){$message = $message + "low"}
- else {$message = $message + "high"}
- }
- }
- }
- #endregion
- #region Menu
- Function Menu-Exchange {
- cls
- "--Exchange Online Admin--"
- "---------------------------------------------------------"
- " 1. Get Mailbox usage"
- " 2. Setup Mail forwarding"
- " 3. Convert a Mailbox and revoke license"
- " 4. Enable Automapping on a Mailbox"
- " 5. Add an Email Alias"
- " 6. Remove an Email Alias"
- " 7. Create a new Distribution Group"
- " 8. Find Groups Where User is a Member"
- " 9. Get Mailbox Usage By License Type"
- "---------------------------------------------------------"
- " --Press R to return to the Main Menu--"
- ""
- $option = Read-Host "Please choose an option"
- switch ($option)
- {
- 1 {MBUsage-Menu}
- 2 {Forward-Mail}
- 3 {Convert-MailboxRemoveLicense}
- 4 {Set-Automap}
- 5 {Add-Alias}
- 6 {Remove-Alias}
- 7 {Create-DistributionGroup}
- 8 {Get-MemberDistGroup}
- 9 {Get-MBUsageByLicense}
- R {Main-Menu}
- default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
- }
- Wait-KeyInput Enter
- }
- Function Menu-SharePoint {
- }
- Function New-365Menu {
- cls
- "--Office 365 Admin--"
- "---------------------------------------------------------"
- " 1. Create a new user"
- " 2. Delete a user"
- " 3. Reset a user password"
- " 4. Get a list of Office 365 users"
- " 5. Remove a license from a user"
- " 6. License all users"
- " 7. Get a CSV of all 365 licenses"
- " 8. Bulk-add New Users from CSV"
- " 9. Get detailed information about a user"
- "---------------------------------------------------------"
- " --Press R to return to the Main Menu--"
- ""
- $option = Read-Host "Please choose an option"
- switch ($option)
- {
- 1 {New-O365User}
- 2 {Delete-User}
- 3 {Reset-O365Password}
- 4 {Get-O365Users}
- 5 {Remove-License}
- 6 {License-AllUsers}
- 7 {Get-O365Licenses}
- 8 {New-UsersBulk}
- 9 {Get-UserInfo}
- R {Main-Menu}
- default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
- }
- Wait-KeyInput
- }
- Function Menu-General {
- }
- Function Menu-Misc {
- cls
- "--Miscellaneous--"
- "---------------------------------------------------------"
- " 1. Play Number Wizard!"
- "---------------------------------------------------------"
- " --Press R to return to the Main Menu--"
- ""
- $option = Read-Host "Please choose an option"
- switch ($option)
- {
- 1 {Number-Wizard}
- R {Main-Menu}
- default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
- }
- Wait-KeyInput
- }
- Function Main-Menu {
- cls
- "Hello, $env:UserName!"
- ""
- "--Main Menu--"
- "---------------------------------------------------------"
- Write-Host " 1. Office 365 Exchange"
- Write-Host " 2. Office 365 SharePoint"
- Write-Host " 3. Office 365 Administration"
- Write-Host " 4. Office 365 Security & Compliance"
- Write-Host " 5. General, Local Administration"
- Write-Host " 6. Miscellaneous Functions"
- "---------------------------------------------------------"
- "--Press E to exit the session--"
- ""
- $answer = Read-Host "Please Make a Selection"
- if ($answer -eq 1){Menu-Exchange}
- if ($answer -eq 2){Menu-SharePoint}
- if ($answer -eq 3){New-365Menu}
- if ($answer -eq 4){Menu-SC}
- if ($answer -eq 5){Menu-General}
- if ($answer -eq 6){Menu-Misc}
- if ($answer -match "E"){Exit-Menu}
- else {Write-Host -ForegroundColor Red "Invalid Selection, please try again!"}
- Wait-KeyInput
- }
- #endregion
- #region Testing and Old Functions
- #Old/Testing Menu's
- Function OldMain-Menu {
- cls
- echo "" #blankline
- echo "Welcome $env:UserName!"
- echo "---------------------------------------------------------"
- echo " 1. Create a new O365 user"
- echo " 2. Delete an O365 user"
- echo " 3. Reset an O365 user's password"
- echo " 4. Convert an O365 mailbox to shared & revoke license"
- echo " 5. Check the time!"
- echo " 6. Get an organised list of O365 Users"
- echo " 7. Play Number Wizard!"
- echo " 8. Get Mailbox Usage for all users"
- echo " 9. Forward Mail to another address"
- echo "" #blankline
- echo " **Press E to exit the session**"
- echo "---------------------------------------------------------"
- $answer = Read-Host "Please Make a Selection"
- if ($answer -eq 1){New-O365User}
- if ($answer -eq 2){Delete-User}
- if ($answer -eq 3){Reset-O365Password}
- if ($answer -eq 4){Convert-MailboxRemoveLicense}
- if ($answer -eq 5){Get-Time}
- if ($answer -eq 6){Get-O365Users}
- if ($answer -eq 7){Number-Wizard}
- if ($answer -eq 8){Write-Host "Please wait, this may take some time.." | Get-MailboxUsage}
- if ($answer -eq 9){Forward-Mail}
- if ($answer -match "e"){Exit-Menu}
- #else {write-host -ForegroundColor red "Invalid Selection"
- Wait-KeyInput
- #sleep 20
- }
- Function Menu-365Admin {
- cls
- echo ""
- echo "--Office 365 Administration--"
- echo "---------------------------------------------------------"
- echo " 1. Create a new user"
- echo " 2. Delete a user"
- echo " 3. Reset a user password"
- echo " 4. Get a list of Office 365 users"
- #echo " 5. Miscellaneous Functions"
- echo "---------------------------------------------------------"
- #echo "" #blankline
- echo "--Press R to return to the Main Menu--"
- ""
- $answer = Read-Host "Please Make a Selection"
- ""
- if ($answer -eq 1){New-O365User}
- elseif ($answer -eq 2){Delete-User}
- elseif ($answer -eq 3){Reset-O365Password}
- elseif ($answer -eq 4){Get-O365Users}
- elseif ($answer -eq "R"){Main-Menu}
- else {Write-Host -ForegroundColor Red "Invalid Selection, please try again!"}
- Wait-KeyInput
- }
- #endregion
- Function Get-MailboxUsage { #Under development
- $mailboxuser = Read-Host "Please enter the mailbox to check or leave blank for all mailboxes"
- $getprohibitsendquota = Read-Host "Would you like to include max mailbox capacity? (Y/N)"
- if ($getprohibitsendquota -eq "Yes") {
- #hashtable array with splat @ - needs reading
- $SO_Params = @{
- Property = 'DisplayName, IsArchiveMailbox, ItemCount, TotalItemSize, ProhibitSendQuota'}}
- else {
- $SO_Params = @{
- Property = 'DisplayName, IsArchiveMailbox, ItemCount, TotalItemSize'}}
- if ($mailboxuser -eq '') {
- Get-Mailbox |
- Get-MailboxStatistics |
- Select-Object @SO_params |
- Format-Table –autosize}
- else {
- Get-Mailbox $mailboxuser |
- Get-MailboxStatistics |
- Select-Object @SO_Params |
- Format-Table –autosize}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement