Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get-serviceInformation {
- [cmdletbinding()]
- param(
- [parameter(ValuefromPipeline)][ValidateNotNullorEmpty()][String[]]$computername = $env:COMPUTERNAME,
- [string[]]$ServiceName
- )
- process {
- $sessions = new-CimSession -ComputerName $computername
- foreach ($s in $sessions)
- {
- if ($ServiceName)
- {
- $service = foreach ($i in $ServiceName)
- {
- Get-CimInstance -ClassName win32_service -CimSession $s -Filter "Name='$($i)'"
- } #foreach servicename
- }# if servicename
- else
- {
- $Service = Get-CimInstance -ClassName win32_service -CimSession $s
- }
- foreach ($i in $Service)
- {
- $obj = '' | select -Property Computername,Service,Description,Runtime,StartMode,Started,Status
- $obj.Computername = $i.PsComputername
- $obj.Service = $i.Name
- $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
- $obj.Status = $i.Status
- $obj.Started = $i.Started
- $obj.Description = $i.Displayname
- $obj.StartMode = $i.StartMode
- $obj
- }#foreach service
- }#foreach session
- $sessions | Remove-CimSession
- }#Process
- }#Function
- function get-DrivespaceInformation {
- [cmdletbinding()]
- param
- (
- [Parameter(ValueFromPipeline)][String[]]$computername
- )
- process{
- New-CimSession -ComputerName $computername | Tee-Object -Variable Session |
- Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
- select @{Name="ComputerName";Expression={$_.PScomputername}},
- @{Name="Drive";Expression={$_.Caption}},
- @{Name="Capacity(GB)";Expression={[Math]::round($_.size/1gb,2) }},
- @{Name="Avilable(GB)";Expression={[Math]::round($_.freespace/1gb,2) }},
- @{Name="Percent free";Expression={[Math]::round($_.freespace/$_.size,3)*100}}
- $session | Remove-CimSession
- }
- }
- $computers = "srv1","srv2","win10"
- $computers | get-DrivespaceInformation | ft
- $computers | get-serviceInformation |ft -GroupBy Computername -AutoSize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement