Advertisement
Guest User

Untitled

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