2015-09-24

Ping servers from a text file

This may look very simple ... but it took me some time to figure out :-(

I am on a Linux box and have a text file with server names / IPs that I want to ping.

How can I do that in a one-liner?

Here is what helped me:

cat [path to textfile] | xargs -n1 ping -c 2


Now I am still looking for a PowerShell one-liner to do something similar.

If you know one, please let me know in the comments.

2015-09-02

Collect disk space data from remote servers

A little PowerShell Script that collects disk space data from remote servers.

I found this practical to collect statistical data.

###############################################################
_#####################
# This script counts and calculated available and free disk
_ spare on remote servers
# # A WMI query is used to collect the data # # Target servers and disks are in a separate comma-delimited
_ text file
###############################################################
_#####################
# Input file location $InputFile = "ServersAndDisks.txt" # Loop through each line of the input file ForEach ($Line in $(Get-Content $InputFile)) { # Write line data into an array $Data = $Line.Split(",") # Get the server name (always first element of the array) $ServerName = $Data[0] write-host $ServerName # Loop through the remaining elements of the array to find
_ available disks
For ($Count = 1; $Count -le $Data.GetUpperBound(0); $Count++) { # Get the disk name $Disk = $Data[$Count] # Run the WMI query $DiskInfo = Get-WmiObject Win32_LogicalDisk -ComputerName
_$ServerName
-Filter "DeviceID='$Disk'" # Do some math on the data $DiskTotal = [math]::Round($DiskInfo.Size / 1GB, 1) $DiskFree = [math]::Round($DiskInfo.FreeSpace / 1GB, 1) $PercentageFree = [math]::Round($DiskInfo.FreeSpace /
_$DiskInfo
.Size * 100, 1) # Output the results Write-Host "$Disk - $DiskTotal GB Total / $DiskFree GB free
_ ($PercentageFree %)"
} }


The input file ServersAndDisks.txt is very simple - only a comma-delimited file with server name and the disks I want to check:
server001,C:,D:
server002,C:,D:
server003,D: