Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Powershell script by DVO
- # Clearing Variables
- $date = "0"
- $hostname = "0"
- $hostdomain = "0"
- $username = "0"
- # Defining Variables
- $version = "1.0"
- $date = Get-Date
- $hostname = $env:COMPUTERNAME
- $hostdomain = $env:USERDOMAIN
- $username = $env:USERNAME
- $build = "21-05-2019"
- $patch = "22-05-2019"
- function checkDomain {
- setdefaultcolor
- if ($hostdomain -ne "companyname") {
- Write-Host -ForegroundColor Red "NOT IN companyname DOMAIN!"
- exitScript
- }else{
- Write-Host -ForegroundColor Green "companyname DOMAIN DETECTED"
- Start-Sleep -Milliseconds 500
- }
- }
- function driveCheck {
- setdefaultcolor
- # Checking if drive is mounted. If not, drive can be mounted.
- Write-Host "Checking if drive is mounted..."
- if(Test-Path B:) {
- Write-Host -ForegroundColor Green "Drive is mounted!"
- Start-Sleep -Milliseconds 500
- writeMenu
- }else{
- Write-Host -ForegroundColor Red "Drive is not mounted!"
- do {
- $mountdrive = Read-Host -Prompt "Would you like to mount the drive now? [Y/N]"
- switch ($mountdrive) {
- "Y" {
- Write-Host "Mapping drive..."
- New-PSDrive -Name "B" -PSProvider FileSystem -Root "\\companyname.local\Logon$" -Scope "Global" -Persist
- Write-Host -ForegroundColor Green "Drive is mounted!"
- Start-Sleep -Milliseconds 500
- writeMenu
- $check = "YES"
- }
- "N" {
- $check = "YES"
- writeMenu
- }
- Default { $check = "NO" }
- }
- } until ($check -eq "YES")
- }
- }
- function setdefaultcolor {
- # Making sure these are the default colors.
- [console]::ForegroundColor = "Magenta"
- [console]::BackgroundColor = "Black"
- }
- function writeIntro {
- # Creating the beautiful start screen :).
- setdefaultcolor
- Clear-Host
- Write-Host "-------------------------------------------------------------------------------------------"
- Write-Host " DVO's Information Toolkit v$version"
- Write-Host "-------------------------------------------------------------------------------------------"
- Write-Host "-- Todays date: $date"
- Write-Host "-- Hostname: $hostname"
- Write-Host "-- Hostdomain: $hostdomain"
- Write-Host "-- Current User: $username"
- Write-Host "-------------------------------------------------------------------------------------------"
- Write-Host "-- Build: $build"
- Write-Host "-- Patch: $patch"
- Write-Host "-------------------------------------------------------------------------------------------"
- Write-Host -ForegroundColor Red "By running this program, you are agreeing that you are authorized to gather information"
- Write-Host "-------------------------------------------------------------------------------------------"
- Write-Host
- }
- function writeMenu {
- setdefaultcolor
- writeIntro
- # Double check if drive is mounted
- if(!(Test-Path B:)) {
- Write-Host -ForegroundColor Red "DRIVE STATUS: UNMOUNTED"
- Write-Host
- }else{
- Write-Host -ForegroundColor Green "DRIVE STATUS: MOUNTED"
- Write-Host
- }
- # Creating the menu
- Write-Host "--- 1 --- Get Logon Information"
- Write-Host "--- 2 --- Get Computer Information"
- Write-Host "--- 3 --- Mount Drive"
- Write-Host "--- 4 --- Unmount Drive"
- Write-Host "--- 5 --- Exit program"
- do {
- $menu = Read-Host "Select option"
- switch ($menu) {
- "1" {
- $value1 = "YES"
- GetLoginInfo
- }
- "2" {
- $value1 = "YES"
- getCompInfo
- }
- "3" {
- $value1 = "YES"
- New-PSDrive -Name "B" -PSProvider FileSystem -Root "\\companyname.local\Logon$" -Scope "Global" -Persist
- Write-Host -ForegroundColor Green "Drive is mounted!"
- Start-Sleep -Seconds 1
- writeMenu
- }
- "4" {
- $value1 = "YES"
- Remove-PSDrive -Name "B" -PSProvider FileSystem -Force
- Write-Host -ForegroundColor GREEN "Drive unmounted!"
- Start-Sleep -Seconds 1
- writeMenu
- }
- "5" {
- $value1 = "YES"
- exitScript
- }
- "r/f" {
- writeMenu
- }
- Default {$value1 = "NO"}
- }
- } until ($value1 -eq "YES")
- }
- function getLoginInfo {
- # Get loggon information from server
- writeIntro
- Write-Host "Please Enter Username (EXAMPLE: DVO). Type [Q] to Quit"
- $user = Read-Host -Prompt "Enter username"
- if($user -eq "Q") {writeMenu}
- $userpath = "B:\User\$user.txt"
- if(Test-Path $userpath) {
- Write-Host -ForegroundColor Green "User Found!"
- Write-Host -ForegroundColor Green "Loading Data..."
- Start-Sleep -Seconds 1
- Clear-Host
- Get-Content $userpath
- $cont = Read-Host -Prompt "Type [Q] to Quit or type [R] to return"
- do {
- switch ($cont) {
- "Q" {
- $cont1 = "1"
- exitScript
- }
- "R" {
- $cont1 = "1"
- GetLoginInfo
- }
- Default { $cont1 = "0"}
- }
- } until ($cont1 -eq "1")
- }else{
- Write-Host -ForegroundColor Red "User not found"
- Start-Sleep -Milliseconds 500
- GetLoginInfo
- }
- }
- function getCompInfo {
- writeIntro
- Write-Host "Please Enter Computername (EXAMPLE: NBX-XXXXXX). Type [Q] to Quit"
- $comp = Read-Host -Prompt "Enter computername"
- if($comp -eq "Q") {writeMenu}
- $comppath = "B:\Computer\$comp.txt"
- if (Test-Path $comppath) {
- Write-Host -ForegroundColor Green "Computer Found!"
- Write-Host -ForegroundColor Green "Loading Data..."
- Start-Sleep -Seconds 1
- Clear-Host
- Get-Content $comppath
- $cont = Read-Host -Prompt "Type [Q] to Quit or type [R] to return"
- do {
- switch ($cont) {
- "Q" {
- $cont1 = "1"
- exitScript
- }
- "R" {
- $cont1 = "1"
- getCompInfo
- }
- Default { $cont1 = "0"}
- }
- } until ($cont1 -eq "1")
- }else{
- Write-Host -ForegroundColor Red "User not found"
- Start-Sleep -Seconds 1
- getCompInfo
- }
- }
- function exitScript {
- [console]::ForegroundColor = "White"
- [console]::BackgroundColor = "Black"
- if(Test-Path B:) {
- Remove-PSDrive -Name "B" -PSProvider FileSystem -Force
- Write-Host -ForegroundColor Red "Exiting..."
- Start-Sleep -Milliseconds 500
- Clear-Host
- Exit-PSSession
- }else{
- Write-Host -ForegroundColor Red "Exiting..."
- Start-Sleep -Milliseconds 500
- Clear-Host
- Exit-PSSession
- }
- }
- function init {
- checkDomain
- driveCheck
- }
- init
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement