Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

not checking each server

$
0
0
clear-host
$VerbosePreference = "continue"
$bansifile= "desktop/result.html"
$global:servers = "BAL-DC-01" , "BAL-NODE-01" , "BAL-NODE-02"
IF (Test-Path $bansifile)
{
	Remove-Item $bansifile
}
$tno = 1"<table border=1 cellpadding=4><tr><th align = center></th><th>Server</th><th>Timezone</th><th>Check_Drive</th><th>IPAddress</th></tr>" >> $bansifile
function woutput([string]$Server,[string]$Timezone,[string]$Check_Drive,[string]$IPAddress)
{"<tr><td align = center>$tno</td><td>"+ $Server + "</td><td>"+ $Timezone + "</td><td>" + $Check_Drive +  "</td><td> "+ $IPAddress +  "</td></tr>" >> $bansifile
}
function get-timezone
{
	Write-Verbose "timezone check - Started"
	foreach($server in $servers)
	{ 
   		$timezoneobj= get-wmiobject win32_timezone -computername $server 
   		$time= $timezoneobj.Caption
	   return ($time)
    }	
    write-Verbose " - Completed"
}
function get-checkdrive
{	
	write-verbose "check drive -started"`
	foreach($server in $servers)
	{    
	    $check='D:\' # no escape 
		$testobj=get-wmiobject win32_volume -filter  "DriveLetter= 'D:'" -computername $server
		$caption= $testobj.Caption
		if($check -contains ($caption) )
		{ 
			$TotalGB=@{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/1073741824),2)}}
			$FreeGB=@{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace /1073741824),2)}}
			$test=$testobj|Select Name , $TotalGB,$FreeGB	
			return ($test)
            write-verbose "check drive -Completed"
		}
        else                
        { 
			write-output "$check doesnt exist"
        }
    }
}
# IPADDRESS
function get-ipaddress
{
	write-verbose "ipaddress check -started"
	foreach ($server in $servers )
    {
		if (test-connection  -computername $server -count 1)
		{  
			$IP = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $server 
			foreach ( $I in $IP)
			{  				
				$IPAddress  = $I.IpAddress[0] 
				[array]$ipv = $IPAddress.Split(" ") | select-string "192"
				  return ($ipv)
            }
        }
		write-verbose "ipaddress obtained -Completed"    
    }
}
$timezone = get-timezone
$check_drive= get-checkdrive
$ipadress= get-ipaddress 
woutput $servers $timezone $check_drive $ipadress 

i get the output as below but its not checking all the servers only one server its checking , i tried "$server ++" but it just not checking all the servers/ please help. 

ServerTimezoneCheck_DriveIPAddress
1BAL-DC-01 BAL-NODE-01 BAL-NODE-02(UTC-08:00) Pacific Time (US & Canada)@{Name=D:\; Capacity(GB)=0; FreeSpace(GB)=0}192.168.1.1

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>