-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabB.ps1
More file actions
70 lines (63 loc) · 2.09 KB
/
Copy pathLabB.ps1
File metadata and controls
70 lines (63 loc) · 2.09 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
function LabB {
<#
.SYNOPSIS
Retrieves Drive, Free Space and Size from one to ten computers.
.DESCRIPTION
LabB uses Windows Management Instrumentation
(WMI) to retrieve information 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
Get-Content names.txt | LabB
.EXAMPLE
LabB -ComputerName SERVER1,SERVER2
#>
[CmdletBinding()]
param(
[Parameter(mandatory=$true,ValueFromPipeline=$true)]
[ValidateCount(1,10)]
[Alias('hostname')]
[string[]]$ComputerName,
[string]$ErrorLog = 'C:\Error.txt'
)
BEGIN {
}
PROCESS {
Write-Verbose "Beginning PROCESS block..."
foreach ($computer in $computername){
Write-Verbose "Querying $computer ..."
try{
$everythingok = $true
$vol = Get-WmiObject -class Win32_Volume -computerName $computer
}
catch{
$everythingok = $false
Write-Warning "COMPUTER FAILED"
$computer | Out-File $ErrorLog
Write-Warning "Errors logged to output file"
}
if($everythingok){
$props = @{'ComputerName'=$computer;
'Drive'=$vol.driveletter;
'FreeSpace'= $vol.freespace;
'Size'=$vol.blocksize}
Write-Verbose "WMI queries complete"
$obj = New-Object -TypeName psobject -Property $props
$obj.PSObject.TypeNames.Insert(0,'MOL.DiskInfo')
Write-Output $obj | Format-Table
}
}
}
END {}
}
Update-FormatData -PrependPath C:\CustomViewB.format.ps1xml
LabB -ComputerName localhost