Showing posts with label Power-Shell. Show all posts
Showing posts with label Power-Shell. Show all posts

Saturday, March 16, 2013

PowerShell Script using WMI class to check uptime of the remote machines - Suptime.ps1

Hello.. Everyone,

Good Day !!!!

I have written one more script to check uptime of the server remote machines that uses PowerShell and WMI class "Win32_OperatingSystem" to check the uptime of the server

The script first checks if the server/computer is reachable then it tries to get uptime of that machine, if the computer/server is not reachable then the script throws a output stating "The server is not reachable"


Content of sutime.ps1
--------------------------------------------------------------------------------
# PS script to get uptime of the computers mentioned in computers.txt file
# Script first checks if the server is reachable then tries to get uptime of the server
# Function to get uptime

Function Get-HostUptime {
    param ([string]$ComputerName)
    $Uptime = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName
    $LastBootUpTime = $Uptime.ConvertToDateTime($Uptime.LastBootUpTime)
    $Time = (Get-Date) - $LastBootUpTime
    Return '{0:00} Days, {1:00} Hours, {2:00} Minutes, {3:00} Seconds' -f $Time.Days, $Time.Hours, $Time.Minutes, $Time.Seconds
}


foreach ($computer in Get-Content "computers.txt")
{
$c = Get-WmiObject Win32_PingStatus -f "Address='$computer'"

if($c.StatusCode -eq 0) 
{

$sysuptime = Get-HostUptime -ComputerName $computer

write-host "$computer" "$sysuptime"
}

else
{

write-host "$computer is not reachable"

}
}

--------------------------------------------------------------------------------

Powershell - Ping servers using wmi class svr-ping.ps1

After a long time this is one new post from me... ;) !!!!
 
Here is one more PowerShell script which uses WMI class PingStatus to check if server is reachable or not remotely 

The computer/server name should be mentioned in "Computers.txt" file

The script can use both IP address or hostname to check the ping status remotely

Ofcourse there are many other ways to ping servers however this is the easiest way I found to be quick way to check the server ping status remotely


Content of svr-ping.ps1

------------------------------------------------------------------------------------
foreach ($computers in Get-Content "Computers.txt")
{

$Computer = Get-WmiObject Win32_PingStatus -f "Address='$computers'"

if($computer.StatusCode -eq 0) 
{
"{0,0} {1,5} {2,5}" -f$computer.Address, $computer.StatusCode, "Its pinging"
}
else
{
"{0,0} {1,5} {2,5}" -f $computer.Address, $computer.StatusCode, "Its not reachable"

}

------------------------------------------------------------------------------------

Sunday, August 26, 2012

Powershell - Invoke command used for Get-AppLockerFileInformation Windows 2008


This script which I have written can be used for getting app-locker event information from remote computers using power-shell on windows 2008 servers.
 
Invoke command calls applocker.ps1 on remote computer mentioned and exports the output to csv format, this can be converted to batch file to run on multiple servers

The .ps1 file and the .csv file will be on the source computer from which we are running this power-shell script. Before you run this script make sure power-shell remote management is enabled on the remote computers.

invoke-command -filepath C:\scripts\applocker.ps1 -computername servername | Export-csv c:\scripts\applocker\servername.csv

Content of applocker.ps1
-----------------------------------------------------------------------------------
Import-Module AppLocker
Get-AppLockerFileInformation -EventLog -LogPath "Microsoft-Windows-AppLocker/EXE and DLL"
Get-AppLockerFileInformation -EventLog -LogPath "Microsoft-Windows-AppLocker/MSI and Script"
-----------------------------------------------------------------------------------

Sunday, August 12, 2012

Get CPU core information using Power-Shell

How to get cpu core information on windows 2003 and 2008 servers ?

The answer is here its just simple we can get CPU core information on all the servers provided in servers.txt file using power-shell script which uses WMI to get CPU core information from remote macines.

Save the below content to file coreinfo.ps1 and mention the server names in servers.txt file
----------------------------------------------------------

$Computers = Get-Content "C:\coreinfo\servers.txt"

ForEach ($cn in $computers)
{

Get-WmiObject Win32_Processor -ComputerName $cn | format-table SystemName, numberofcores, NumberOfLogicalProcessors –AutoSize
}
----------------------------------------------------------

The above script has been tested on windows 2008 servers and works perfectly fine

To run this script on Windows 2003 server machines you need to install below mentioned patches(whichever applies)

Windows 2003 Sp2 
http://support.microsoft.com/kb/936235 
http://support.microsoft.com/kb/932370