Advertisement
Guest User

getInformation Script

a guest
May 22nd, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Powershell script by DVO
  2.  
  3. # Clearing Variables
  4. $date = "0"
  5. $hostname = "0"
  6. $hostdomain = "0"
  7. $username = "0"
  8.  
  9.  
  10. # Defining Variables
  11. $version = "1.0"
  12. $date = Get-Date
  13. $hostname = $env:COMPUTERNAME
  14. $hostdomain = $env:USERDOMAIN
  15. $username = $env:USERNAME
  16. $build = "21-05-2019"
  17. $patch = "22-05-2019"
  18.  
  19. function checkDomain {
  20.     setdefaultcolor
  21.     if ($hostdomain -ne "companyname") {
  22.         Write-Host -ForegroundColor Red "NOT IN companyname DOMAIN!"
  23.         exitScript
  24.     }else{
  25.         Write-Host -ForegroundColor Green "companyname DOMAIN DETECTED"
  26.         Start-Sleep -Milliseconds 500
  27.     }
  28. }
  29.  
  30. function driveCheck {
  31.     setdefaultcolor
  32.     #  Checking if drive is mounted. If not, drive can be mounted.
  33.     Write-Host "Checking if drive is mounted..."
  34.     if(Test-Path B:) {
  35.         Write-Host -ForegroundColor Green "Drive is mounted!"
  36.         Start-Sleep -Milliseconds 500
  37.         writeMenu
  38.     }else{
  39.         Write-Host -ForegroundColor Red "Drive is not mounted!"
  40.         do {
  41.             $mountdrive = Read-Host -Prompt "Would you like to mount the drive now? [Y/N]"
  42.             switch ($mountdrive) {
  43.                 "Y" {
  44.                     Write-Host "Mapping drive..."
  45.                     New-PSDrive -Name "B" -PSProvider FileSystem -Root "\\companyname.local\Logon$" -Scope "Global" -Persist
  46.                     Write-Host -ForegroundColor Green "Drive is mounted!"
  47.                     Start-Sleep -Milliseconds 500
  48.                     writeMenu
  49.                     $check = "YES"
  50.                 }
  51.                 "N" {
  52.                     $check = "YES"
  53.                     writeMenu
  54.                 }
  55.                 Default { $check = "NO" }
  56.             }
  57.         } until ($check -eq "YES")
  58.     }
  59. }
  60.  
  61. function setdefaultcolor {
  62.     #  Making sure these are the default colors.
  63.     [console]::ForegroundColor = "Magenta"
  64.     [console]::BackgroundColor = "Black"
  65. }
  66.  
  67. function writeIntro {
  68.     #  Creating the beautiful start screen :).
  69.     setdefaultcolor
  70.     Clear-Host
  71.     Write-Host "-------------------------------------------------------------------------------------------"
  72.     Write-Host "                          DVO's Information Toolkit v$version"
  73.     Write-Host "-------------------------------------------------------------------------------------------"
  74.     Write-Host "--  Todays date:            $date"
  75.     Write-Host "--  Hostname:               $hostname"
  76.     Write-Host "--  Hostdomain:             $hostdomain"
  77.     Write-Host "--  Current User:           $username"
  78.     Write-Host "-------------------------------------------------------------------------------------------"
  79.     Write-Host "--  Build:                  $build"
  80.     Write-Host "--  Patch:                  $patch"
  81.     Write-Host "-------------------------------------------------------------------------------------------"
  82.     Write-Host -ForegroundColor Red "By running this program, you are agreeing that you are authorized to gather information"
  83.     Write-Host "-------------------------------------------------------------------------------------------"
  84.     Write-Host
  85. }
  86.  
  87. function writeMenu {
  88.     setdefaultcolor
  89.     writeIntro
  90.     #  Double check if drive is mounted
  91.     if(!(Test-Path B:)) {
  92.         Write-Host -ForegroundColor Red "DRIVE STATUS: UNMOUNTED"
  93.         Write-Host
  94.     }else{
  95.         Write-Host -ForegroundColor Green "DRIVE STATUS: MOUNTED"
  96.         Write-Host
  97.     }
  98.  
  99.    
  100.     #  Creating the menu
  101.     Write-Host "---   1   ---   Get Logon Information"
  102.     Write-Host "---   2   ---   Get Computer Information"
  103.     Write-Host "---   3   ---   Mount Drive"
  104.     Write-Host "---   4   ---   Unmount Drive"
  105.     Write-Host "---   5   ---   Exit program"
  106.     do {
  107.         $menu = Read-Host "Select option"
  108.         switch ($menu) {
  109.             "1" {
  110.                 $value1 = "YES"
  111.                 GetLoginInfo
  112.             }
  113.             "2" {
  114.                 $value1 = "YES"
  115.                 getCompInfo
  116.             }
  117.             "3" {
  118.                 $value1 = "YES"
  119.                 New-PSDrive -Name "B" -PSProvider FileSystem -Root "\\companyname.local\Logon$" -Scope "Global" -Persist
  120.                 Write-Host -ForegroundColor Green "Drive is mounted!"
  121.                 Start-Sleep -Seconds 1
  122.                 writeMenu
  123.             }
  124.             "4" {
  125.                 $value1 = "YES"
  126.                 Remove-PSDrive -Name "B" -PSProvider FileSystem -Force
  127.                 Write-Host -ForegroundColor GREEN "Drive unmounted!"
  128.                 Start-Sleep -Seconds 1
  129.                 writeMenu
  130.             }
  131.             "5" {
  132.                 $value1 = "YES"
  133.                 exitScript
  134.             }
  135.             "r/f" {
  136.                 writeMenu
  137.             }
  138.             Default {$value1 = "NO"}
  139.     }
  140.     } until ($value1 -eq "YES")
  141. }
  142.  
  143. function getLoginInfo {
  144.     # Get loggon information from server
  145.     writeIntro
  146.     Write-Host "Please Enter Username (EXAMPLE: DVO). Type [Q] to Quit"
  147.     $user = Read-Host -Prompt "Enter username"
  148.     if($user -eq "Q") {writeMenu}
  149.     $userpath = "B:\User\$user.txt"
  150.     if(Test-Path $userpath) {
  151.         Write-Host -ForegroundColor Green "User Found!"
  152.         Write-Host -ForegroundColor Green "Loading Data..."
  153.         Start-Sleep -Seconds 1
  154.         Clear-Host
  155.         Get-Content $userpath
  156.         $cont = Read-Host -Prompt "Type [Q] to Quit or type [R] to return"
  157.         do {
  158.             switch ($cont) {
  159.                 "Q" {
  160.                     $cont1 = "1"
  161.                     exitScript
  162.                 }
  163.                 "R" {
  164.                     $cont1 = "1"
  165.                     GetLoginInfo
  166.                 }
  167.                 Default { $cont1 = "0"}
  168.             }
  169.         } until ($cont1 -eq "1")
  170.     }else{
  171.         Write-Host -ForegroundColor Red "User not found"
  172.         Start-Sleep -Milliseconds 500
  173.         GetLoginInfo
  174.     }
  175. }
  176.  
  177. function getCompInfo {
  178.     writeIntro
  179.     Write-Host "Please Enter Computername (EXAMPLE: NBX-XXXXXX). Type [Q] to Quit"
  180.     $comp = Read-Host -Prompt "Enter computername"
  181.     if($comp -eq "Q") {writeMenu}
  182.     $comppath = "B:\Computer\$comp.txt"
  183.     if (Test-Path $comppath) {
  184.         Write-Host -ForegroundColor Green "Computer Found!"
  185.         Write-Host -ForegroundColor Green "Loading Data..."
  186.         Start-Sleep -Seconds 1
  187.         Clear-Host
  188.         Get-Content $comppath
  189.         $cont = Read-Host -Prompt "Type [Q] to Quit or type [R] to return"
  190.         do {
  191.             switch ($cont) {
  192.                 "Q" {
  193.                     $cont1 = "1"
  194.                     exitScript
  195.                 }
  196.                 "R" {
  197.                     $cont1 = "1"
  198.                     getCompInfo
  199.                 }
  200.                 Default { $cont1 = "0"}
  201.             }
  202.         } until ($cont1 -eq "1")
  203.  
  204.     }else{
  205.         Write-Host -ForegroundColor Red "User not found"
  206.         Start-Sleep -Seconds 1
  207.         getCompInfo
  208.     }
  209. }
  210. function exitScript {
  211.     [console]::ForegroundColor = "White"
  212.     [console]::BackgroundColor = "Black"
  213.     if(Test-Path B:) {
  214.         Remove-PSDrive -Name "B" -PSProvider FileSystem -Force
  215.         Write-Host -ForegroundColor Red "Exiting..."
  216.         Start-Sleep -Milliseconds 500
  217.         Clear-Host
  218.         Exit-PSSession
  219.     }else{
  220.         Write-Host -ForegroundColor Red "Exiting..."
  221.         Start-Sleep -Milliseconds 500
  222.         Clear-Host
  223.         Exit-PSSession
  224.     }
  225. }
  226.  
  227. function init {
  228.     checkDomain
  229.     driveCheck
  230. }
  231.  
  232. init
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement