SHARE
TWEET

Untitled

a guest Dec 5th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function PS-Session{ #Creates interactive Session
  2.     Param(
  3.     [Parameter(Mandatory=$true,
  4.         HelpMessage="Enter the computer name you wish to connect too")]
  5.         [string]$ComputerName,
  6.  
  7.     [Parameter(Mandatory=$true,
  8.         HelpMessage = "Enter your credentials")]
  9.         [string]$Credentials
  10.     )
  11.     New-PSSession -ComputerName $ComputerName -Credential $Credentials
  12.  
  13.     while($loop){
  14.     Clear-Host
  15.     [int]$loop = Read-Host "Input 0 to disconnect"
  16.     }
  17.     Get-PSSession -ComputerName -Credential | Disconnect-PSSession -Session
  18.  
  19. }#End of Session
  20.  
  21. Function Populate{
  22. Set-Location "C:\Users\$env:USERNAME\Documents"
  23.  
  24. $Header =@"
  25. ===================================
  26. Header Header Header Header Header
  27. ===================================
  28. "@
  29.  
  30. #Creating the 15 files
  31. for($i = 1; $i -ne 6; $i++){
  32. New-Item -Force "File$i.txt"
  33. New-Item -Force "File$i.DOCX"
  34. New-Item -Force "File$i.PS1"
  35.  
  36.  Write-Output "$Header" > File$i.TXT
  37.  Write-Output "$Header" > File$i.DOCX
  38.  Write-Output "$Header" > File$i.PS1
  39.  
  40.  $MyArr+= "Files$i.TXT"
  41.  $MyArr+= "Files$i.DOCX "
  42.  $MyArr+= "Files$i.PS1 "
  43. [array]$FileArray = $MyArr -Split(" ")
  44.  
  45. }
  46.  
  47. }#End of Populate
  48.  
  49. Function TreeCheckandFill{ #Uses the files made in populate. Finds or creates the proper tree system for them and then copies them over.
  50.  
  51. $Populate = Read-Host "Populate? [Y]es [N]o"
  52. if($Populate -eq "Y"){
  53.     Populate
  54. }
  55. #Testing if Win213 Directory exists
  56. $DirectoryCheck = 0;
  57. if(Test-Path "Win213_Files" -PathType Container){
  58.     $DirectoryCheck = 1;
  59. }
  60. Write-Host $DirectoryCheck
  61.  
  62. if($DirectoryCheck -eq 0){
  63.    
  64.     New-Item -ItemType Directory "Win213_Files"
  65.     New-Item -ItemType Directory -Path "Win213_Files\TXT"
  66.     New-Item -ItemType Directory -Path "Win213_Files\DOCX"
  67.     New-Item -ItemType Directory -Path "Win213_Files\PS1"
  68.  
  69. }else{
  70. $Answer = Read-host "Tree exists do you wish to populate? [Y]es"
  71.     if($Answer -eq "Y"){
  72.     $Date = Get-Date -UFormat "%A %m/%d/%Y %R %Z"
  73.  
  74.     if(-not(Test-Path "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt")){
  75.         New-Item -Path "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  76.     }
  77.  
  78.         for($i = 1; $i -lt 6; $i+= 1){
  79.             Copy-Item "File$i.TXT" "Win213_Files\TXT"
  80.             Write-Output "$Date, Created File$1.TXT" >> "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  81.            
  82.             Copy-Item "File$i.DOCX" "Win213_Files\DOCX"
  83.             Write-Output "$Date, Created File$1.DOCX" >> "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  84.            
  85.             Copy-Item "File$i.PS1" "Win213_Files\PS1"
  86.             Write-Output "$Date, Created File$1.PS1" >> "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  87.         }
  88.     }
  89.  }
  90.  
  91. }#End of Tree check and fill
  92.  
  93. Function SysInv{
  94.     Get-AdComputer
  95.     $Test = Test-Connection "Computer" -Quiet -Count 1
  96.     if ($test){
  97.     "Online"
  98.     }else{
  99.         "Offline"
  100.         }
  101.  
  102. }#End of SysInv NOT COMPLETE
  103.  
  104. Function Delete{ #Takes file input and finds+removes that file
  105. Set-Location "C:\Users\$env:USERNAME\Documents"
  106.     [string]$Garbage = Read-Host("Input the files you wish to be deleted. #E.G *2.TXT, *3.DOCX")
  107.     $MyArr = $Garbage -split(",")
  108.  
  109.     Get-ChildItem $Garbage -Recurse | Remove-Item #Searchs for inputed item in the Document Location
  110.     if(Get-ChildItem $Garbage -Recurse){
  111.          $Date = Get-Date -UFormat "%A %m/%d/%Y %R %Z"
  112.  
  113.         if(-not(Test-Path "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt")){
  114.             New-Item -Path "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  115.              Write-Output "$Date, User deleted file $Garbage" >> "C:\Users\$env:USERNAME\AppData\Local\Temp\Log.txt"
  116.         }
  117.     }
  118.  
  119. }#End of Delete
  120.  
  121. Function Menu{
  122.  
  123.  
  124. $menu = @"
  125. ++++++++++++++++++++++
  126. `t`t`t Menu `t`t`t
  127. ++++++++++++++++++++++
  128.  
  129. [1]Start PS-Session
  130. [2]Check Directory
  131. [3]System Inventory
  132. [4]Delete Files
  133. [5]Exit
  134.  
  135. "@
  136. do{
  137.    Clear-Host
  138.    Write-host -BackgroundColor Black -ForegroundColor White $menu
  139.    $input = Read-Host
  140.   switch($input)
  141.   {
  142.     '1'{PS-Session;pause;break;}
  143.     '2'{TreeCheckandFill;pause;break;}
  144.     '3'{SysInv;pause;break;}
  145.     '4'{Delete;pause;break;}
  146.   }
  147.  
  148. }while($input -ne "5")
  149. }#End of Menu
  150.  
  151. Menu
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