-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabC.ps1
More file actions
79 lines (70 loc) · 2.41 KB
/
Copy pathLabC.ps1
File metadata and controls
79 lines (70 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function LabC {
<#
.SYNOPSIS
Retrieves Running System Services from one to ten computers.
.DESCRIPTION
LabB uses Get-Service to retrieve running services from one or
more computers. Specify computers by name or by IP address.
.PARAMETER ComputerName
One or more computer names or IP addresses, up to a maximum
of 10.
.PARAMETER LogErrors
Specify this switch to create a text log file of computers
that could not be queried.
.PARAMETER ErrorLog
When used with -LogErrors, specifies the file path and name
to which failed computer names will be written. Defaults to
C:\Retry.txt.
.EXAMPLE
LabC -ComputerName SERVER1,SERVER2
#>
[CmdletBinding()]
param(
[Parameter(mandatory=$true,ValueFromPipeline=$true)]
[ValidateCount(1,10)]
[Alias('hostname')]
[string[]]$ComputerName,
[string]$ErrorFile = 'C:\Errors.txt',
[switch]$LogErrors
)
BEGIN {
}
PROCESS {
Write-Verbose "Beginning PROCESS block..."
foreach ($computer in $computername){
Write-Verbose "Querying $computer ..."
if($LogErrors){
$ErrorFile.Remove()
}
try{
$everythingok = $true
$serv = Get-Service | Where-Object -filter {$_.status -eq 'Running'}
}
catch{
$everythingok = $false
Write-Warning "COMPUTER FAILED"
if($LogErrors){
$computer | Out-File $ErrorLog -Append
Write-Warning "Errors logged to output file"
}
}
if($everythingok){
$props = @{'ComputerName'=$computer;
'Service'=$serv.ServiceName;
'DisplayName'= $serv.DisplayName;
'ProcessName'=$serv.ServiceName;
'VMSize'=$serv.MachineName;
'ThreadCount'=$serv.CanPauseAndContinue;
'PeakPageFile'=$serv.Container}
$obj = New-Object -TypeName psobject -Property $props
$obj.PSObject.TypeNames.Insert(0,'MOL.ServiceProcessInfo')
Write-Output $obj
Write-Verbose "Service queries complete"
}
}
}
END {}
}
Update-FormatData -PrependPath c:\CustomViewC.format.ps1xml
LabC -ComputerName localhost
LabC -ComputerName localhost | Format-List