SHARE
TWEET

Untitled

a guest Jun 16th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $List = @(Cat -Path C:\Scripts\Lists\Enviros.txt)
  2.  
  3. function Show-Menu {
  4.     param (
  5.         [string]$Title = 'Server Choices'
  6.     )
  7.     $Listcount = ($List.Count - 1)
  8.     cls
  9.     #using namespace System.Collections.Generic
  10.     $ListVals = [List[int]]@(0..$Listcount)
  11.     Write-Host "================ $Title ================"
  12.     for ($ListVal = 0; $ListVal -lt $List.length; $Listval++) {
  13.         #$ListVal in $ListVals)
  14.         Write-Host $ListVal": Press $ListVal for" $List[$ListVal]"."
  15.     }
  16.     Write-Host "Q: Press 'Q' to quit."        
  17. }
  18.    
  19. do {
  20.     Show-Menu
  21.  
  22.     $input = Read-Host "Please make a selection"
  23.     switch ($input) {
  24.         '1' {
  25.             cls
  26.             $NewValue = $input
  27.             'You chose option #1 for ' + "$NewValue"
  28.                
  29.         } '2' {
  30.             cls
  31.             'You chose option #2'
  32.         } '3' {
  33.             cls
  34.             'You chose option #3'
  35.         }'4' {
  36.             cls
  37.             'You chose option #4'
  38.         } '5' {
  39.             cls
  40.             'You chose option #5'
  41.         } '6' {
  42.             cls
  43.             'You chose option #6'
  44.         } '7' {
  45.             cls
  46.             'You chose option #7'
  47.         } '8' {
  48.             cls
  49.             'You chose option #8'
  50.         } '9' {
  51.             cls
  52.             'You chose option #9'
  53.         } '0' {
  54.             cls
  55.             'You chose option #0'
  56.             $enviro = Read-Host "What Environment? Prod or Lab?"
  57.             if ($enviro -like "Lab") {
  58.                 $domain = 'ucn\'
  59.                 $user = [Environment]::UserName
  60.                 $username = $domain + $user
  61.    
  62.                 $password = Get-Content C:\Users\$user\Documents\inucn.txt | ConvertTo-SecureString
  63.                 $inucnCred = New-Object -typename System.Management.Automation.PSCredential `
  64.                     -argumentlist $username, $password
  65.        
  66.                 $VCs = 'eng-vmvce01.in.lab'
  67.                 foreach ($vc in $vcs) {
  68.                     Connect-VIServer -Server $VC -Credential $inucnCred
  69.                 }
  70.             }
  71.    
  72.             else {
  73.                 $domain = 'inucn.com'
  74.                 $user = [Environment]::UserName
  75.                 $username = $user + '@' + $domain
  76.                 $VCs = 'lax-vmvce01.inucn.com', 'dal-vmvce01.inucn.com'
  77.    
  78.                 $password = Get-Content C:\Users\$user\Documents\inucn.txt | ConvertTo-SecureString
  79.                 $inucnCred = New-Object -typename System.Management.Automation.PSCredential `
  80.                     -argumentlist $username, $password
  81.        
  82.                 foreach ($vc in $vcs) {
  83.                     Connect-VIServer -Server $VC -Credential $inucnCred
  84.                 }
  85.             }
  86.    
  87.             $Servername = Read-Host "What computers do you want to get?"
  88.    
  89.             $outFile = "\\corpfs03.ucn.net\DFS-Root\AppOps\Engage\Tools\Scripts\Lists\$servername" + "list.csv"
  90.    
  91.             foreach ($Vc in $Vcs) {
  92.                 $Servers = Get-VM -Name "*$Servername*" -Server $Vc | Select Name
  93.                 $Servers | Out-File $outFile
  94.                 Write-Host "Your file is located @ $outFile"
  95.             }
  96.         }
  97.         'q' {
  98.             return
  99.         }
  100.     }
  101.     pause
  102. }
  103. until ($input -eq 'q')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top