Guest User

Untitled

a guest
Aug 3rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. function Get-LinuxProcesses {
  2.  
  3. <#
  4.  
  5. .NOTES
  6. Plink Help File
  7. Plink: command-line connection utility
  8. Release 0.70
  9. Usage: plink [options] [user@]host [command]
  10. ("host" can also be a PuTTY saved session name)
  11. Options:
  12. -V print version information and exit
  13. -pgpfp print PGP key fingerprints and exit
  14. -v show verbose messages
  15. -load sessname Load settings from saved session
  16. -ssh -telnet -rlogin -raw -serial
  17. force use of a particular protocol
  18. -P port connect to specified port
  19. -l user connect with specified username
  20. -batch disable all interactive prompts
  21. -proxycmd command
  22. use 'command' as local proxy
  23. -sercfg configuration-string (e.g. 19200,8,n,1,X)
  24. Specify the serial configuration (serial only)
  25. The following options only apply to SSH connections:
  26. -pw passw login with specified password
  27. -D [listen-IP:]listen-port
  28. Dynamic SOCKS-based port forwarding
  29. -L [listen-IP:]listen-port:host:port
  30. Forward local port to remote address
  31. -R [listen-IP:]listen-port:host:port
  32. Forward remote port to local address
  33. -X -x enable / disable X11 forwarding
  34. -A -a enable / disable agent forwarding
  35. -t -T enable / disable pty allocation
  36. -1 -2 force use of particular protocol version
  37. -4 -6 force use of IPv4 or IPv6
  38. -C enable compression
  39. -i key private key file for user authentication
  40. -noagent disable use of Pageant
  41. -agent enable use of Pageant
  42. -hostkey aa:bb:cc:...
  43. manually specify a host key (may be repeated)
  44. -m file read remote command(s) from file
  45. -s remote command is an SSH subsystem (SSH-2 only)
  46. -N don't start a shell/command (SSH-2 only)
  47. -nc host:port
  48. open tunnel in place of session (SSH-2 only)
  49. -sshlog file
  50. -sshrawlog file
  51. log protocol details to a file
  52. -shareexists
  53. test whether a connection-sharing upstream exists
  54. #>
  55.  
  56. [CmdletBinding()]
  57. param([parameter()]
  58. [string]$ComputerName
  59. [parameter(Mandatory = $true)]
  60. [string]$Target,
  61. [parameter(Mandatory = $true)]
  62. [object]$Credentials,
  63. [parameter()]
  64. [ValidateScript({Test-Path $_ })]
  65. [string[]]$PLinkPath = "C:\Program Files\PuTTY\plink.exe"
  66. )
  67.  
  68. $UserName = $Credentials.GetNetworkCredential().UserName
  69. $Password = $Credentials.GetNetworkCredential().Password
  70.  
  71. #Command for grabbing process information
  72. $nixProcsCmd = "`& `$PLinkPath `$UserName@`$ComputerName -pw `$Password"
  73. $nixProcsCmd += " `"ps -Ao `'%U,%P,%p,%t,%a`'`" 2> `$Null"
  74.  
  75. #Enumerate known host keys stored in Registry
  76. Write-Verbose "Checking Registry for $ComputerName known host key"
  77. $KeysRegistry = (Get-ChildItem -Path "HKCU:\Software\SimonTatham\PuTTY").Property
  78. $KeysRegistry = $KeysRegistry | ForEach { $_ -replace ".+?:","" }
  79.  
  80. #If ComputerName wasn't in the known host keys, prepend "echo y" to accept the remote host
  81. #key prior to running process command to avoid user interaction requirement
  82. if($ComputerName -notin $KeysRegistry){ $nixProcsCmd = "echo y | $nixProcsCmd" }
  83.  
  84. Write-Verbose "Collecting Process Information"
  85. $processlist = Invoke-Expression $nixProcsCmd
  86. $processlist = $processlist | ConvertFrom-Csv
  87.  
  88. #Append Collection Timestamp
  89. $timestamp = (Get-Date).ToString()
  90. $processlist = $processlist | Add-Member -MemberType NoteProperty -Name "CollectionTimestamp" -value $timestamp
  91.  
  92. return $processlist
  93.  
  94. }
Add Comment
Please, Sign In to add comment