tastydoosh

PSBibleJH

Nov 28th, 2018
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Cd 'C:\Users\JamieHutchinson\Documents\WindowsPowerShell'
  2. #To Begin, CD to desktop, dot-source PS Bible v5.2.ps1, then type SelectCustomer and press enter.
  3.  
  4. #region
  5. #Script Functions
  6. Function SelectCustomer {
  7.     cls
  8.         echo ""
  9.         Write-Host "Please select a customer and press enter." -ForegroundColor Cyan
  10.         echo ""
  11.         echo "    1. Customer 1                                         01234 567 891"
  12.         echo "    2. Customer 2                                         09843 123 123"
  13.         echo ""
  14.         Write-Host "   -Or select M to skip signing in and head straight for the main menu-" -ForegroundColor Magenta
  15.  
  16. "`n"
  17.  
  18. $customer = Read-Host "Enter the number relating to the customer"
  19.  
  20.     if ($customer -eq 1){$loginwith = 'admin@company1.onmicrosoft.com'}
  21.     if ($customer -eq 2){$loginwith = 'admin@company2.onmicrosoft.com'}
  22.  
  23.  
  24.     if ($customer -eq "M"){Main-Menu}
  25.     if ($customer -eq "m"){Main-Menu}
  26.  
  27.     if ($customer -gt "21"){Write-Host -ForegroundColor Red "Invalid Selection, please try again!" | SelectCustomer}
  28.  
  29.         $O365Cred = Get-Credential -UserName $loginwith -Message "Enter your Office 365 Admin Password for $loginwith"
  30.  
  31.                 $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange  `
  32.                                             -ConnectionUri https://ps.outlook.com/powershell  `
  33.                                             -Credential $O365Cred -Authentication Basic  `
  34.                                             -AllowRedirection  `
  35.        
  36.         Connect-MsolService -Credential $O365Cred
  37.  
  38.             Import-Module MSOnline
  39.             Import-PSSession $O365Session
  40.        
  41.         Get-MsolDomain
  42.  
  43.             "" # Blank Line
  44.             "Welcome " + $env:UserName + "!"
  45.                     Write-Host "`n"
  46.             "The the time is currently " + "{0:HH}:{0:mm} GMT" -f (Get-Date)
  47.                     Main-Menu
  48.             "`n" # Blank Line
  49. }
  50. Function Clear-UserVariables {
  51.          
  52.          $x=powershell -nologo -command "gv|out-string"
  53.          $y=($x|select -skip 15) -split "\s+",2
  54.          $varnames = $(for ($i=0;$i -lt $y.length; $i+=2) { $y[$i]})
  55.          rv i,x,y
  56.          gv | % {if ($varnames -notcontains $_.name) {rv $_.name -EA 0}}
  57.          }
  58. Function Disconnect-ExchangeOnline {
  59. ;
  60.          Get-PSSession | Where-Object {$_.ConfigurationName -eq “Microsoft.Exchange”} |
  61.                 Remove-PSSession
  62. }
  63. Function Wait-KeyInput {
  64.  
  65. Read-Host "Press Enter to return to the Main Menu"
  66.  
  67.     Main-Menu
  68.  
  69. }
  70. Function Exit-Menu {$ExitMenu = read-host "Are you sure you want to exit? (y/n)"  
  71.            if ($ExitMenu -eq "y"){exit}  
  72.            if ($ExitMenu -eq "n"){Main-Menu}  
  73.            else {write-host -foregroundcolor red "Invalid Selection"  
  74.                  areyousure}
  75. }
  76. Function Get-Time {
  77.           Write-Host "`n"
  78.             "The time is currently " + "{0:HH}:{0:mm} GMT" -f (Get-Date)
  79. }
  80. Function MBUsage-Menu { cls
  81.  
  82. Write-Host "Would you like to find information on a particular user or all mailboxes?"
  83. ""
  84. "--Get Mailbox Statistics--"
  85. "---------------------------------------------------------"  
  86.         echo "    1. Single User"
  87.         echo "    2. All Mailboxes"
  88. "---------------------------------------------------------"
  89. #echo ""   #blankline
  90. echo "--Press R to return to the Main Menu--"
  91. ""
  92. $answer = Read-Host "Please make a selection"
  93.    
  94.         if ($answer -eq 1){Get-SingleMBStat}
  95.         if ($answer -eq 2){Get-AllMBStat}
  96.         if ($answer -eq "R"){Main-Menu}
  97.  
  98. }
  99. #endregion
  100.  
  101. #region
  102. #Office 365 Exchange
  103. Function Convert-MailboxRemoveLicense {
  104.          
  105.          $emailaddress = Read-Host -Prompt 'Please enter the username'
  106.             "`n"
  107.          $mbname = $emailaddress
  108.                  
  109.          $sharedanswer = Read-Host -Prompt 'Would you like to convert this user to a shared mailbox?(Yes/No)'
  110.                          If($sharedanswer -eq "Yes"){Set-Mailbox -Identity $mbname -Type Shared -Force}
  111.  
  112.                          #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
  113.          
  114.             "`n"
  115.          $assignedlicenses = Get-MsolUser -UserPrincipalName $emailaddress
  116.          $assignedlicenses.Licenses.AccountSkuId
  117.             "`n"
  118.                          $licensetoremove = Read-Host -Prompt "Please type the license you wish to remove"
  119.                          Set-MsolUserLicense -UserPrincipalName $emailaddress -RemoveLicenses $licensetoremove
  120.             "`n"
  121.          Write-Host "$licensetoremove has been revoked from $emailaddress"  `
  122.                     -BackgroundColor Green -ForegroundColor White
  123.             "`n"
  124.          $mbtype = Get-Mailbox -Identity $mbname | Select-Object RecipientTypeDetails
  125.          Write-Host "Mailbox: $emailaddress has been converted."
  126.          $mbtype
  127.  
  128.          Main-Menu
  129. }
  130.  
  131. Function Get-AllMBStat {
  132.  
  133. Write-Host "Please wait, this may take some time..." -ForegroundColor Green
  134.  
  135. Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, ItemCount, TotalItemSize, ProhibitSendQuota  |
  136.     Out-GridView
  137. }
  138.  
  139. Function Get-SingleMBStat {
  140.  
  141.          $mailboxuser = Read-Host "Please enter the mailbox to check"
  142.  
  143.          Get-Mailbox $mailboxuser | Get-MailboxStatistics | Select-Object DisplayName,  `
  144.          ItemCount, TotalItemSize, ProhibitSendQuota | Format-Table –autosize
  145.  
  146. }
  147.  
  148. Function Get-MBUsageByLicense {
  149.  
  150.             $var1 = Get-MsolAccountSku
  151.             Write-Host $var1
  152.  
  153.             $var1.AccountSkuID, $var1.ActiveUnits, $var1.ConsumedUnits
  154.  
  155. $licensetype = Read-Host "Enter company name and license type, i.e. Contoso:O365_BUSINESS_PREMIUM"
  156.  
  157.     $licensedUsers = Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" }
  158.     $enterpriseUsers = $licensedUsers | Where-Object { $_.Licenses.AccountSkuId -eq "$licensetype" }
  159.  
  160. $mbStats = @()
  161.  
  162. foreach ($user in $enterpriseUsers) {
  163.   $mbStats += get-mailbox $user.signinname | get-mailboxstatistics |
  164.    select-object displayname, itemcount, totalitemsize, ProhibitSendQuota, mailboxguid
  165. }
  166.  
  167. $mbStats | select-object displayname, itemcount, totalitemsize, prohibitsendquota |
  168.   Sort-Object TotalItemSize | format-table -AutoSize
  169.  
  170. }
  171.  
  172. Function Forward-Mail {
  173.  
  174.          $forwardfrom = Read-Host "Please enter the email address to forward from"
  175.          $forwardto = Read-Host "Please enter the email address to forward to"
  176.          $deliverandforward = Read-Host "Do you wish to deliver to initial mailbox and forward? (True/false)"
  177.  
  178.                       If ($deliverandforward -eq "True"){[bool]$deliverandforward = 1}
  179.                         Else{[bool] $deliverandforward = 0}
  180.  
  181.          Set-Mailbox -Identity $forwardfrom  `
  182.                      -ForwardingSmtpAddress $forwardto  `
  183.                      -DeliverToMailboxAndForward $deliverandforward
  184.  
  185.          Write-Host $forwardfrom {Get-Mailbox -Identity $forwardfrom | FL ForwardingSMTPAddress}
  186.  
  187. }
  188. Function Set-Automap {
  189.  
  190.               $Mapmailbox = Read-Host "Please enter the mailbox you would like to automap"
  191.               $Mapto = Read-Host "Please enter the user you would like the mailbox mapped to"
  192.  
  193.         Add-MailboxPermission $Mapmailbox -User $Mapto -AccessRights FullAccess -AutoMapping $true
  194.  
  195.         Write-Host "$Mapmailbox has been automapped to $Mapto with FullAccess Permissions."
  196. }
  197.  
  198. Function Add-Alias {
  199.                $SelectMailbox = Read-Host "Enter the primary mailbox"
  200.  
  201.                            Get-Mailbox $SelectMailbox | Select -ExpandProperty Emailaddresses Alias
  202.  
  203.                $AliasToAdd = Read-Host "Please type in the alias you would like to add"
  204.  
  205.                Set-Mailbox $SelectMailbox -EmailAddresses @{Add=$AliasToAdd}
  206.                Write-Host $AliasToAdd has been added as an alias to $SelectMailbox. -ForegroundColor Green
  207. }
  208.  
  209. Function Remove-Alias {
  210.                $SelectMailbox = Read-Host "Enter the primary mailbox"
  211.  
  212.                Write-Host "Please be aware the, addresses with SMTP in capitals are PRIMARY" -ForegroundColor Red
  213.  
  214.                            Get-Mailbox $SelectMailbox | Select -ExpandProperty Emailaddresses Alias
  215.  
  216.                $AliasToRemove = Read-Host "Please enter the alias you would like to remove"
  217.  
  218.                Set-Mailbox $SelectMailbox -EmailAddresses @{Remove=$aliastoremove}
  219.                Write-Host $AliasToRemove has been removed as an alias from $SelectMailbox. -ForegroundColor Green
  220. }
  221.  
  222. Function Create-DistributionGroup { #Under construction#
  223.  
  224.                $distgroupname = Read-Host "Please enter a name for the new Distribution Group"
  225.                $primarysmtp = Read-Host "Please choose a primary email address for the group"
  226.                $externalsend = Read-Host "Can this group receive mail from external addresses (True/False)?"
  227.  
  228.                     If ($externalsend -eq "True"){[bool]$externalsend = 1}
  229.                     Else{[bool] $externalsend = 0}
  230.  
  231.                New-DistributionGroup -Name $distgroupname -DisplayName $distgroupname  `
  232.                                                       -PrimarySmtpAddress $primarysmtp  `
  233.                                                       -RequireSenderAuthenticationEnabled $externalsend
  234.  
  235.                Write-Host "Your new distribution group, $distgroupname has been created, now let's add some members"  `
  236.               -ForegroundColor Green
  237.  
  238.               $members = Read-Host "Please enter the members separated by commas and contained in double quote marks"
  239.  
  240.               Add-DistributionGroupMember -Identity $primarysmtp -Member $members
  241. }
  242.  
  243. function Get-MemberDistGroup {
  244.  
  245.     [CmdletBinding()]
  246.     Param(
  247.         [Parameter(Mandatory=$true)]
  248.         [Alias('Email')]
  249.         [string]$UserName
  250.     )
  251.         $user = Get-User $username; $groups = Get-Group | Where-Object {$_.Members -contains $user}
  252.  
  253.     Write-Host "If no results appear. try invoking cmdlet manually with Get-MemberDistGroup" -ForegroundColor Cyan -NoNewline
  254.         foreach ($group in $groups) {
  255.         $props = @{'Name'           = $group.Name;
  256.      
  257.                    'PrimaryEmail'   = $group.WindowsEmailAddress}
  258.  
  259.         $obj = New-Object -TypeName PSObject -Property $props
  260.         Write-Output $obj
  261.     }
  262. }
  263.  
  264. #endregion
  265.  
  266. #region
  267. #Office 365 Administration
  268.  
  269. Function New-O365User {
  270.  
  271.          $firstname = Read-Host -Prompt 'Enter the first name'
  272.          $lastname = Read-Host -Prompt 'Enter the last name'
  273.          $primaryemail = Read-Host -Prompt 'Enter the desired email address, i.e. Firstname.lastname@company.com'
  274.          $displayname = -join("$firstname", " ", "$lastname")
  275.          $usagelocation = Read-Host -Prompt 'Enter the usage location (GB/US/ETC.)'
  276.  
  277.             $var1 = Get-MsolAccountSku
  278.             Write-Host $var1
  279.  
  280.                 $var1.AccountSkuID, $var1.ActiveUnits, $var1.ConsumedUnits
  281.              
  282.          $license = Read-Host -Prompt 'Enter license type'
  283.          $password = Read-Host -Prompt 'Choose a password'
  284.          $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
  285.  
  286.                 IF($answer -eq "True"){[bool]$forcechangepassword = 1}  `
  287.                 Else{[bool]$forcechangepassword = 0}
  288.  
  289.          $answer2 = Read-Host -Prompt 'Do you wish for this password to expire every 90 days? (True/False)'
  290.                 If($answer2  -eq "True"){[bool]$passwordexpiry = 1}  `
  291.                 Else{[bool]$passwordexpiry = 0}
  292.  
  293.  
  294.           New-MsolUser -FirstName $firstname  `
  295.                        -LastName $lastname  `
  296.                        -DisplayName $displayname  `
  297.                        -UserPrincipalName $primaryemail  `
  298.                        -UsageLocation $usagelocation  `
  299.                        -LicenseAssignment $license  `
  300.                        -Password $password  `
  301.                        -ForceChangePassword $forcechangepassword  `
  302.                        -PasswordNeverExpires $passwordexpiry
  303.  
  304.           Write-Host –NoNewLine  “A new user has been created: Username: $userprincipalname, Password: $password”  `
  305.           -BackgroundColor “Green” -ForegroundColor “Black”
  306.  
  307.           Clear-UserVariables                          
  308.      
  309.          }
  310. Function New-UsersBulk {
  311. ""
  312. Write-Host -ForegroundColor Green "- Create a CSV with the following columns:"
  313. Write-Host -ForegroundColor Green "   UserPrincipalName, FirstName, LastName, DisplayName"
  314. Write-Host -ForegroundColor Green "- Save the CSV as, C:\IMPORTUSERS.CSV"
  315.  
  316.     Get-MsolDomain | Format-Table -AutoSize
  317.     Write-Host "Check that the domain used in CSV matches available domains"
  318.  
  319.     $continue = Read-Host "Ready to proceed? (Y/N)"
  320.        
  321.         if ($continue -eq "Y") {
  322.  
  323.     $users  = Import-Csv C:\ImportUsers.csv
  324.  
  325.         Write-Host -ForegroundColor Magenta "Reading CSV and Importing Users"
  326.         Write-Host -ForegroundColor Magenta "Creating New Users... Please wait,"
  327.  
  328.     $users | ForEach-Object {
  329.  
  330.         New-MsolUser -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName  `
  331.                                   -UserPrincipalName $_.UserPrincipalName}
  332.     }
  333.        
  334.         elseif ($continue -eq "N") {Main-Menu}
  335.         else {Write-Host -ForegroundColor Red "Invalid Input detected" | New-UsersBulk}
  336.  
  337. }
  338. Function Delete-User { #needs work
  339.  
  340.          $usertodelete = Read-Host -Prompt 'Please enter the user email address'
  341.          $permdelete = Read-Host -Prompt 'Would you like to permanently delete the user? Yes/No'
  342.                        If($answer -eq "Yes"){[bool]$permdelete = 1}  `
  343.                        Else{[bool]$permdelete = 0}
  344.  
  345.          Remove-MsolUser -UserPrincipalName $usertodelete
  346.  
  347.          #-RemoveFromRecycleBin $permdelete
  348.          
  349.          Write-Host –NoNewLine  “$usertodelete has been deleted.”  `
  350.           -BackgroundColor “Green” -ForegroundColor “Black”
  351.  
  352.          }
  353. Function Reset-O365Password {
  354.  
  355. #Start Menu
  356.  
  357.          $usertoreset = Read-Host -Prompt "Please enter the username required for password reset"
  358.          $newpassword = Read-Host -Prompt "Please enter a new password or leave blank for a random password"
  359.          
  360.          
  361.          $answer = Read-Host -Prompt 'Do you wish the user to change password upon next login? (True/False)'
  362.                 IF($answer -eq "True"){[bool]$forcechangepassword = 1}  `
  363.                 Else{[bool]$forcechangepassword = 0}
  364.          
  365.          Set-MsolUserPassword -UserPrincipalName $usertoreset  `
  366.                               -NewPassword $newpassword  `
  367.                               -ForceChangePassword $forcechangepassword  `
  368.  
  369.          Write-Host "Password for user: $usertoreset has been set to $newpassword successfully" -BackgroundColor Green -ForegroundColor White
  370.  
  371. }
  372. Function Get-O365Users {
  373.  
  374.          Get-Mailbox | Select-Object DisplayName, UserPrincipalName | Sort-Object DisplayName | Format-Table –autosize
  375.  
  376.          }
  377. Function Remove-License { #under development
  378.          
  379.          $emailaddress = Read-Host -Prompt 'Please enter the username'
  380.  
  381.          Write-Host "`n"
  382.  
  383.             Write-Host "Currently assigned licenses:" -BackgroundColor "Green" -ForegroundColor Black
  384.             Get-MsolUser -UserPrincipalName $emailaddress | Format-List Licenses
  385.  
  386.          $licensename = Read-Host -Prompt 'Please enter the license name you wish to remove'
  387.  
  388.                         Write-Host "`n"
  389.  
  390.          Set-MsolUserLicense -UserPrincipalName $emailaddress  `
  391.                              -RemoveLicenses $licensename
  392.  
  393.          Write-Host –NoNewLine  “$licensename has been removed from the user $emailaddress”  `
  394.           -BackgroundColor “Green” -ForegroundColor “Black”
  395.  
  396.           Write-Host "`n"
  397.  
  398.          $deleteanswer = Read-Host -Prompt 'Would you like to delete this user?(Yes/No)'
  399.                          If($deleteanswer -eq "Yes"){[bool]$deleteanswer = 1}
  400.                          Else{[bool]$deleteanswer = 0}
  401.  
  402.          $sharedanswer = Read-Host -Prompt 'Would you like to convert this user to a shared mailbox?(Yes/No)'
  403.                          If($sharedanswer -eq "Yes"){Set-Mailbox -Identity $emailaddress -Type Shared -Force}
  404.  
  405.          Get-MsolUser -UserPrincipalName $emailaddress
  406.          Get-Mailbox -Identity $emailaddress | Format-List RecipientTypeDetails
  407.  
  408.          }
  409. Function License-AllUsers { foreach ($o in (Get-MsolUser -UnlicensedUsersOnly)){Set-MsolUser -
  410.         UserPrincipalName $o.UserPrincipalName -UsageLocation GB ; SetMsolUserLicense
  411.         -UserPrincipalName $o.UserPrincipalName -AddLicenses
  412.         (Get-MsolAccountSku).AccountSkuId}
  413.         }
  414. Function Get-O365Licenses {
  415. $LogFile = "C:\users\JamieHutchinson\Desktop\O365_Licenses.csv"
  416.     write-host "Connecting to Office 365..."
  417.  
  418. $licensetype = Get-MsolAccountSku | Where {$_.ConsumedUnits -ge 1}
  419.  
  420.     foreach ($license in $licensetype)  {    
  421.     $headerstring = "DisplayName,UserPrincipalName,AccountSku"
  422.      
  423.     foreach ($row in $($license.ServiceStatus))  {
  424.         $headerstring = ($headerstring + "," + $row.ServicePlan.servicename) }
  425.      
  426.     Out-File -FilePath $LogFile -InputObject $headerstring -Encoding UTF8 -append
  427.     write-host ("Gathering users with the following subscription: " + $license.accountskuid)
  428.  
  429.     $users = Get-MsolUser -all | where {$_.isLicensed -eq "True" -and $_.licenses.accountskuid -contains $license.accountskuid}
  430.  
  431.     foreach ($user in $users) {
  432.          
  433.         write-host ("Processing " + $user.displayname)
  434.  
  435.         $thislicense = $user.licenses | Where-Object {$_.accountskuid -eq $license.accountskuid}
  436.         $datastring = ($user.displayname + "," + $user.userprincipalname + "," + $license.SkuPartNumber)
  437.          
  438.             foreach ($row in $($thislicense.servicestatus)) {
  439.              
  440.             $datastring = ($datastring + "," + $($row.provisioningstatus))}
  441.          
  442.     Out-File -FilePath $LogFile -InputObject $datastring -Encoding UTF8 -append}
  443.     Out-File -FilePath $LogFile -InputObject " " -Encoding UTF8 -append}            
  444.  
  445.     write-host ("Script Completed.  Results available in " + $psdir + $LogFile) -ForegroundColor Green
  446. }
  447.  
  448. Function Get-UserInfo {
  449.  
  450.     $usernameforinfo = Read-Host "Enter the username to retrieve information"
  451.                 Get-MsolUser -UserPrincipalName $usernameforinfo | Format-List *
  452. }
  453. #endregion
  454.  
  455. #region
  456. #Security and Compliance
  457.  
  458. Function Enable-LitigationHold {
  459.  
  460.     $mailboxforhold = Read-Host "Please enter the mailbox name"
  461.     $holdduration = Read-Host "Please enter the duration of hold (days)"
  462.     $confirmhold = Read-Host "Please confirm you would like to place a litagation hold of $holdduration days on mailbox $mailboxforhold"
  463.            
  464.             If ($confirmhold -eq "Yes"){Confirm-Hold}
  465.             Else {Write-Host -ForegroundColor Red "Invalid Selection"}
  466. }      
  467.             function Confirm-Hold {
  468.  
  469.             Set-Mailbox -Identity $mailboxforhold -LitigationHoldEnabled $true -LitigationHoldDuration $holdduration
  470.             Write-Host "Mailbox $mailboxforhold is now enabled for Litigation Hold for $holdduration"
  471.  
  472.             Wait-KeyInput
  473.  
  474.             Main-Menu
  475.       }
  476.  
  477.  
  478. #endregion
  479.                      
  480. #region
  481. #Miscellaneous Functions
  482.  
  483. Function Generate-Password {
  484.  
  485. Write-Host "Choose two words that you will remember using capital letters at the beginning of both"
  486. Write-Host "a password will be generated with your memorable words." -NoNewline
  487.  
  488. $wordonesecure = Read-Host "Please type the first word in your password" -AsSecureString
  489. $wordtwosecure = Read-Host "Please type the second word in your password" -AsSecureString
  490. $wordthreesecure = Read-Host "Please type the third word in your password" -AsSecureString
  491.  
  492.         $wordonedecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordonesecure))
  493.         $wordtwodecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordtwosecure))
  494.         $wordthreedecrypted = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($wordthreesecure))
  495.  
  496.                 $securestring = New-SWRandomPassword
  497.  
  498.         $securepassword = -join("$wordonedecrypted", "$wordtwodecrypted", "$wordthreedecrypted", "$securestring")
  499.         ""
  500. Write-Host "Your new password has been generated:"
  501. Write-Host "$securepassword" -ForegroundColor Green
  502.  
  503. }
  504.  
  505. Function Number-Wizard {  
  506.  
  507. Clear-Host
  508.  
  509. #Initialize replay variable so that the game plays at least once
  510.  
  511. $replay = 1
  512.  
  513. ## Main game loop here that runs until user decides to quit.
  514. While($replay -ne 0) {
  515.     #Initializing pre-game variables
  516.     $secretNumber = Get-Random -Minimum 1 -Maximum 100
  517.     $closeHigh = $secretNumber + 10
  518.     $closeLow = $secretNumber - 10
  519.     $guesses = @()
  520.     $message = ""
  521.     $quit = 0
  522.  
  523.     #Sub game loop that makes up one time through the game
  524.     While($quit -ne 1){
  525.            
  526.             $guess = ''
  527.             Clear-Host
  528.             Write-Host -NoNewline "`t`t`tHenlo $env:UserName, welcome to my guessing game!"
  529.             if ($guesses.Count -ne 0){
  530.                 Write-Host "You have guessed" $guesses.Count "time(s)"
  531.                 Write-Host "Your past guesses were:"$guesses
  532.                
  533.             }
  534.             Write-Host "`n" $message "`n"
  535.  
  536.            #Take user input.  Currently very unsanitary and unexpected input could result in unexpected behavior
  537.             While($guess -eq ''){
  538.                 $guess = Read-Host "Please guess a number between 1 and 100 (or type q to exit) and press enter"
  539.                 if ($guess -eq "q"){
  540.                     $quit = 1
  541.                     $replay = 0
  542.                 }else{
  543.                     $guessint = [int]$guess
  544.                 }
  545.                
  546.             }
  547.             #Add the guess from this cycle to the list of past guesses
  548.             $guesses = $guesses + $guessint          
  549.  
  550.             #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
  551.             if($guessint -eq $secretNumber) {
  552.                 $quit = 1
  553.                 $playagain = ''
  554.                 While(($playagain -ne "y") -and ($playagain -ne "n")){
  555.                     Clear-Host
  556.                     Write-Host "`n`t`tYou Win!!!"
  557.                     Write-Host "You won the game after" $guesses.Count "guesses!"
  558.                     Write-Host "`nDo you want to try again?"
  559.                     $playagain = Read-Host "Please type Y for yes or N for no and press enter"
  560.                 }
  561.                 if ($playagain -eq "y"){
  562.                     break
  563.                 } else {
  564.                     $replay = 0
  565.                 }
  566.  
  567.                 # Proximity handling to build feedback for the user
  568.             } elseif(($guessint -le $closeHigh) -and ($guessint -gt $closeLow)) {
  569.                 $message = "You're getting close! Just a bit too "
  570.             } else {
  571.                 $message = "Way too "
  572.             }
  573.             if($guessint -lt $secretNumber){$message = $message + "low"}
  574.             else {$message = $message + "high"}
  575.  
  576.  
  577.         }
  578.  
  579.     }
  580. }
  581. #endregion
  582.          
  583. #region Menu
  584.  
  585. Function Menu-Exchange {
  586. cls
  587. "--Exchange Online Admin--"
  588. "---------------------------------------------------------"  
  589. "    1. Get Mailbox usage"
  590. "    2. Setup Mail forwarding"
  591. "    3. Convert a Mailbox and revoke license"
  592. "    4. Enable Automapping on a Mailbox"
  593. "    5. Add an Email Alias"
  594. "    6. Remove an Email Alias"
  595. "    7. Create a new Distribution Group"
  596. "    8. Find Groups Where User is a Member"
  597. "    9. Get Mailbox Usage By License Type"
  598. "---------------------------------------------------------"  
  599. "   --Press R to return to the Main Menu--"
  600. ""
  601. $option = Read-Host "Please choose an option"
  602.  
  603. switch ($option)
  604.        {
  605.         1 {MBUsage-Menu}
  606.         2 {Forward-Mail}
  607.         3 {Convert-MailboxRemoveLicense}
  608.         4 {Set-Automap}
  609.         5 {Add-Alias}
  610.         6 {Remove-Alias}
  611.         7 {Create-DistributionGroup}
  612.         8 {Get-MemberDistGroup}
  613.         9 {Get-MBUsageByLicense}
  614.         R {Main-Menu}
  615.         default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
  616.         }
  617.         Wait-KeyInput Enter
  618. }
  619. Function Menu-SharePoint {
  620. }
  621. Function New-365Menu {
  622. cls
  623. "--Office 365 Admin--"
  624. "---------------------------------------------------------"  
  625. "    1. Create a new user"
  626. "    2. Delete a user"
  627. "    3. Reset a user password"
  628. "    4. Get a list of Office 365 users"
  629. "    5. Remove a license from a user"
  630. "    6. License all users"
  631. "    7. Get a CSV of all 365 licenses"
  632. "    8. Bulk-add New Users from CSV"
  633. "    9. Get detailed information about a user"
  634. "---------------------------------------------------------"  
  635. "   --Press R to return to the Main Menu--"
  636. ""
  637. $option = Read-Host "Please choose an option"
  638.  
  639. switch ($option)
  640.        {
  641.         1 {New-O365User}
  642.         2 {Delete-User}
  643.         3 {Reset-O365Password}
  644.         4 {Get-O365Users}
  645.         5 {Remove-License}
  646.         6 {License-AllUsers}
  647.         7 {Get-O365Licenses}
  648.         8 {New-UsersBulk}
  649.         9 {Get-UserInfo}
  650.         R {Main-Menu}
  651.         default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
  652.         }
  653.         Wait-KeyInput
  654. }
  655. Function Menu-General {
  656. }
  657. Function Menu-Misc {
  658.  
  659. cls
  660. "--Miscellaneous--"
  661. "---------------------------------------------------------"  
  662. "    1. Play Number Wizard!"
  663. "---------------------------------------------------------"  
  664. "   --Press R to return to the Main Menu--"
  665. ""
  666. $option = Read-Host "Please choose an option"
  667.  
  668. switch ($option)
  669.        {
  670.         1 {Number-Wizard}
  671.         R {Main-Menu}
  672.         default {Write-Host -ForegroundColor Red "Invalid Selection, please try again"}
  673.         }
  674.         Wait-KeyInput
  675.  
  676. }
  677. Function Main-Menu {
  678. cls
  679.  "Hello, $env:UserName!"
  680.  ""
  681.  "--Main Menu--"
  682.  "---------------------------------------------------------"  
  683. Write-Host "    1. Office 365 Exchange"
  684. Write-Host "    2. Office 365 SharePoint"
  685. Write-Host "    3. Office 365 Administration"
  686. Write-Host "    4. Office 365 Security & Compliance"
  687. Write-Host "    5. General, Local Administration"
  688. Write-Host "    6. Miscellaneous Functions"
  689.  "---------------------------------------------------------"
  690.  
  691. "--Press E to exit the session--"
  692.  
  693.         ""
  694.         $answer = Read-Host  "Please Make a Selection"
  695.            
  696.             if ($answer -eq 1){Menu-Exchange}
  697.             if ($answer -eq 2){Menu-SharePoint}
  698.             if ($answer -eq 3){New-365Menu}
  699.             if ($answer -eq 4){Menu-SC}
  700.             if ($answer -eq 5){Menu-General}
  701.             if ($answer -eq 6){Menu-Misc}
  702.            
  703.                 if ($answer -match "E"){Exit-Menu}
  704.                 else {Write-Host -ForegroundColor Red "Invalid Selection, please try again!"}
  705.  
  706.         Wait-KeyInput
  707. }
  708. #endregion
  709.  
  710. #region Testing and Old Functions
  711.  
  712. #Old/Testing Menu's
  713. Function OldMain-Menu {  
  714.  cls  
  715.  echo "" #blankline
  716.  echo "Welcome $env:UserName!"
  717.  echo "---------------------------------------------------------"  
  718.  echo "    1. Create a new O365 user"  
  719.  echo "    2. Delete an O365 user"
  720.  echo "    3. Reset an O365 user's password"
  721.  echo "    4. Convert an O365 mailbox to shared & revoke license"
  722.  echo "    5. Check the time!"
  723.  echo "    6. Get an organised list of O365 Users"
  724.  echo "    7. Play Number Wizard!"
  725.  echo "    8. Get Mailbox Usage for all users"
  726.  echo "    9. Forward Mail to another address"
  727.  echo ""   #blankline
  728.  echo "    **Press E to exit the session**"  
  729.  echo "---------------------------------------------------------"  
  730.  $answer = Read-Host "Please Make a Selection"  
  731.  if ($answer -eq 1){New-O365User}  
  732.  if ($answer -eq 2){Delete-User}
  733.  if ($answer -eq 3){Reset-O365Password}
  734.  if ($answer -eq 4){Convert-MailboxRemoveLicense}
  735.  if ($answer -eq 5){Get-Time}
  736.  if ($answer -eq 6){Get-O365Users}
  737.  if ($answer -eq 7){Number-Wizard}
  738.  if ($answer -eq 8){Write-Host "Please wait, this may take some time.." | Get-MailboxUsage}
  739.  if ($answer -eq 9){Forward-Mail}
  740.  if ($answer -match "e"){Exit-Menu}  
  741.  #else {write-host -ForegroundColor red "Invalid Selection"
  742.  
  743.     Wait-KeyInput
  744.    
  745.        #sleep 20  
  746.  }
  747. Function Menu-365Admin {
  748. cls
  749. echo ""
  750. echo "--Office 365 Administration--"
  751. echo "---------------------------------------------------------"  
  752. echo "    1. Create a new user"
  753. echo "    2. Delete a user"
  754. echo "    3. Reset a user password"
  755. echo "    4. Get a list of Office 365 users"
  756. #echo "    5. Miscellaneous Functions"
  757. echo "---------------------------------------------------------"
  758. #echo ""   #blankline
  759. echo "--Press R to return to the Main Menu--"
  760.  
  761.         ""
  762.         $answer = Read-Host  "Please Make a Selection"
  763.         ""    
  764.             if ($answer -eq 1){New-O365User}
  765.              
  766.                 elseif ($answer -eq 2){Delete-User}
  767.                 elseif ($answer -eq 3){Reset-O365Password}
  768.                 elseif ($answer -eq 4){Get-O365Users}
  769.                 elseif ($answer -eq "R"){Main-Menu}
  770.  
  771.                 else {Write-Host -ForegroundColor Red "Invalid Selection, please try again!"}
  772.  
  773.         Wait-KeyInput
  774. }
  775. #endregion
  776.  
  777. Function Get-MailboxUsage { #Under development
  778.  
  779.     $mailboxuser = Read-Host "Please enter the mailbox to check or leave blank for all mailboxes"
  780.     $getprohibitsendquota = Read-Host "Would you like to include max mailbox capacity? (Y/N)"
  781.  
  782.     if ($getprohibitsendquota -eq "Yes") {
  783.  
  784.             #hashtable array with splat @ - needs reading
  785.  
  786.             $SO_Params = @{
  787.             Property = 'DisplayName, IsArchiveMailbox, ItemCount, TotalItemSize, ProhibitSendQuota'}}
  788.  
  789.     else {
  790.  
  791.             $SO_Params = @{
  792.             Property = 'DisplayName, IsArchiveMailbox, ItemCount, TotalItemSize'}}
  793.  
  794.     if ($mailboxuser -eq '') {
  795.             Get-Mailbox |
  796.             Get-MailboxStatistics |
  797.             Select-Object @SO_params |
  798.             Format-Table –autosize}
  799.     else {
  800.             Get-Mailbox $mailboxuser |
  801.             Get-MailboxStatistics |
  802.             Select-Object @SO_Params |
  803.             Format-Table –autosize}
  804.     }
Add Comment
Please, Sign In to add comment