header image

W2KSG: Using Array

Posted by: | August 27, 2008 | No Comment |

If we want to extend our disk checking to multiple machines we can input the computer names via an array.

Script Center Home > Microsoft Windows 2000 Scripting Guide > Scripting Concepts and Technologies for System Administration > VBScript Primer > VBScript Overview Arrays

## listing 2.12

$convert = 1MB
$computers = "pcrs2", "pcrs3", "pcrs4"
$threshold = 100

foreach ($computer in $computers) {
    $disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk
    foreach ($disk in $disks) {
        $free = [int]($disk.Freespace/$convert)
        if ($free -lt $threshold){Write-Host "$computer $($disk.DeviceID) is low on diskspace"}

We then do a simple foreach loop for each computer in the array and substitute its name into Get-WMIObject.  Note that the -Computername parameter of Get-WMIObject does not accept pipeline input so we need a foreach of some kind


Share this post :


Technorati Tags:

under: PowerShell original