Guest User

Invoke-MachineDump

a guest
Jan 31st, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Invoke-MachineDump
  2.  {
  3.  
  4.      [CmdletBinding()]
  5.      param
  6.      (
  7.          [Parameter(Mandatory=$True,
  8.          ValueFromPipeline=$True,
  9.          ValueFromPipelineByPropertyName=$True,
  10.          HelpMessage='Please Enter a Machine Name')]
  11.          [string]$machine
  12.      )
  13.  
  14.     #Object for storing computer/logtype information
  15.     $logRepo = "\\$server\$directoryPath..."
  16.     $date = get-date -format MMddyyyy
  17.     $logs = "\\OtherPC\C$\Logs"
  18.     $machineDir = "$logRepo\$machine-$date"
  19.     #Check for destination directory and create if not found
  20.     if(!(Test-Path -Path $machineDir ))
  21.     {
  22.         try
  23.         {
  24.             New-Item -ItemType directory -Path $machineDir -ErrorAction Stop
  25.         }
  26.         catch
  27.         {
  28.             write-host "Directory already exists"
  29.         }
  30.     }
  31.  
  32.     ########################################################
  33.     ### TODO Return object for point and shoot functionality
  34.     ########################################################
  35.     $returnObj = New-Object -TypeName psobject -Property @{
  36.         computername = "$computer"
  37.         windowsVersion = "$winVer"
  38.         processList = "$procList"
  39.         serviceList = "$serviceList"
  40.     }
  41.  
  42.    
  43.     $installLogs = Get-ChildItem "c:\logs" -filter "*.log" | select-object Name
  44.  
  45.     ###################################################
  46.     ###       Control Flow for Copying
  47.     ###################################################
  48.     foreach($file in $installLogs)
  49.     {
  50.         $f = $file.Name
  51.         copy-item "$logs\$f" -destination $machineDir -recurse          
  52.     }
  53.  
  54.  
  55.     ###################################################
  56.     ### Get running processes/services from remote machine
  57.     ###################################################
  58.     get-process -computername $goPC | out-file "$machineDir\Processes.log"
  59.     get-service -computername $goPC | where {$_.Status -eq "Running"} |  out-file "$machineDir\Services.log"
  60.  
  61.     return $returnObj
  62. }
Add Comment
Please, Sign In to add comment