Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. function get-serviceInformation {
  2. [cmdletbinding()]
  3. param(
  4. [parameter(ValuefromPipeline)][ValidateNotNullorEmpty()][String[]]$computername = $env:COMPUTERNAME,
  5. [string[]]$ServiceName
  6. )
  7.  
  8. process {
  9. $sessions = new-CimSession -ComputerName $computername
  10. foreach ($s in $sessions)
  11. {
  12.  
  13. if ($ServiceName)
  14. {
  15. $service = foreach ($i in $ServiceName)
  16. {
  17. Get-CimInstance -ClassName win32_service -CimSession $s -Filter "Name='$($i)'"
  18. } #foreach servicename
  19. }# if servicename
  20. else
  21. {
  22. $Service = Get-CimInstance -ClassName win32_service -CimSession $s
  23. }
  24.  
  25. foreach ($i in $Service)
  26. {
  27.  
  28. $obj = '' | select -Property Computername,Service,Description,Runtime,StartMode,Started,Status
  29. $obj.Computername = $i.PsComputername
  30. $obj.Service = $i.Name
  31. $obj.Runtime =$($($(get-date) - $(Get-CimInstance -Query "SELECT * from Win32_Process WHERE ProcessId LIKE '$($i.ProcessId)'" -CimSession $s | select CreationDate).CreationDate | select @{Name="Runtime";Expression={"[$($_.Days) Day(s) $($_.Hours) Hours $($_.Minutes) Min]"}})).Runtime
  32. $obj.Status = $i.Status
  33. $obj.Started = $i.Started
  34. $obj.Description = $i.Displayname
  35. $obj.StartMode = $i.StartMode
  36.  
  37. $obj
  38. }#foreach service
  39. }#foreach session
  40. $sessions | Remove-CimSession
  41. }#Process
  42. }#Function
  43.  
  44. function get-DrivespaceInformation {
  45. [cmdletbinding()]
  46. param
  47. (
  48. [Parameter(ValueFromPipeline)][String[]]$computername
  49. )
  50. process{
  51. New-CimSession -ComputerName $computername | Tee-Object -Variable Session |
  52. Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
  53. select @{Name="ComputerName";Expression={$_.PScomputername}},
  54. @{Name="Drive";Expression={$_.Caption}},
  55. @{Name="Capacity(GB)";Expression={[Math]::round($_.size/1gb,2) }},
  56. @{Name="Avilable(GB)";Expression={[Math]::round($_.freespace/1gb,2) }},
  57. @{Name="Percent free";Expression={[Math]::round($_.freespace/$_.size,3)*100}}
  58. $session | Remove-CimSession
  59. }
  60. }
  61.  
  62.  
  63.  
  64. $computers = "srv1","srv2","win10"
  65.  
  66. $computers | get-DrivespaceInformation | ft
  67. $computers | get-serviceInformation |ft -GroupBy Computername -AutoSize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement