Wednesday, 24 February 2016

Testing purpose


$process= Get-Process -Name notepad -ComputerName server1

if($process)

{


schtasks /run /s dc.superdc.com /TN Service



}



else


{

Restart-Computer -Force -ComputerName server1

}





$process= Get-Process -Name notepad -ComputerName server2



if($process)

{


schtasks /run /s dc.superdc.com /TN Service



}



else


{

Restart-Computer -Force -ComputerName server2

}

Wednesday, 17 February 2016

Getting service status in HTML format and sending to mail

$a = "<style>"
$a = $a + "BODY{background-color:Green;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 2;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"



$comp = Get-Content -Path C:\serverslist.txt

$m=foreach ($c in $comp)
{
Get-Service -ComputerName $comp | select-object machinename,Name,Status| Where-Object {$_.status -eq "running"} | ConvertTo-Html -head $a
}

Send-MailMessage -to "administrator@superdc.com"  -From "DG_ADMINS@superdc.com" -BodyAsHtml "$m" -Subject "Servicestatus" -SmtpServer "dc.superdc.com"

code in ISE

 I
output

Friday, 6 November 2015

How to shutdown Multilple computers using Powershell

$computers = Get-Content "C:\computers.txt"

$offline =@()

foreach ($computer in $computers)



{

if (Test-Connection $computer -Count 3 -ea 0) {

Stop-Computer -ComputerName $computers



}

else {

$offline+= "$computer not reachable"



}}

Wednesday, 29 July 2015

How to get Total installed memory on remote systems and export to csv


$computers= Get-Content -Path C:\servers.txt

$info=@()

foreach($computer in $computers){
$colItems = get-wmiobject -class "Win32_ComputerSystem" -namespace "root\CIMV2" -computername $computer

foreach ($objItem in $colItems){
$displayGB = [math]::round($objItem.TotalPhysicalMemory/1024/1024/1024, 0)
$res = "" | select Computer,Memory
$res.computer = $computer
$res.Memory = $displayGB

$info +=$res

}
}
$info | Export-Csv c:\12.csv -NoTypeInformation

Tuesday, 9 June 2015

Getting Disk space from Local system

If you want to get the list of disks and their use age use following script

get-wmiobject win32_logicaldisk -Filter "Drivetype=3" -ComputerName "localhost" | select systemName,deviceid,volumename,@{Name ="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},
@{Name="Freespace(Gb)";Expression={"{0:N1}" -f($_.freespace/1gb)}} | Format-Table -AutoSize


Output will be

Sunday, 20 April 2014

Save and clear Eventlogs

Hello friends

This time i am posting "How to save and clear Eventlogs"

if most of your production servers are running on VM (virtualmachines) the space on OS drive (C) may reach above threshhold in that case you need to
clear some space.we can clear temp files and compress some logs.apart doing
all these we can create a powershellscript to save and clear eventlogs.


$applog=Get-WmiObject win32_nteventlogfile -Filter "logfilename = 'application'"
$date=Get-Date -Format ("dd-MM-yyy-mm-ss")
$applog.backupeventlog("d:\Applicationlog_$date.evtx")
$applog=Get-WmiObject win32_nteventlogfile -Filter "logfilename ='system'"
$applog.backupeventlog("d:\systemlog_$date.evtx")

Clear-EventLog -Log application,system






 

Friday, 21 March 2014

Resetting ILO's from Command Line

Last week i got a request from Application team to reboot few HP servers.

usually we use shutdown -i -r from run to reboot i have initiated the reboot and waited for more than  30 minutes but system is not coming up machine was in hung state. I tried to restart the machine using ILO. Unfortunately ILO is also not 
helping.then I seek one of my colleges help in resolving this issue and this is very good tip.

we can restart  machine using ILO commands.

use plink utility to login to the ILO.

HP Servers

Plink to the ILO ip with ID/Password.

 Plink 1.2.3.4 ( iloipaddress)


provide username and password


it will take you to the prompt :
</>hpiLO-> cd /map1
status=0
status_tag=COMMAND COMPLETED

</map1>hpiLO-> reset
status=0
status_tag=COMMAND COMPLETED
Resetting iLO. 

CLI session stopped.
You can even shutdown/restrat the server from here.
For more commands   type "help"


thanks to my brother AZAM

Sunday, 22 December 2013

How to stop or start a specifc service on local as well on remote systems

This time I am posting Powershell Script on How to stop or start  a specifc service on local as well on remote systems

 

Get-Service -Name w32time
 
Output
 
PS C:\Users\administrator> Get-Service -Name w32time
Status   Name               DisplayName                          
------   ----               -----------                          
Running  w32time            Windows Time       

 
For stopping
 
Get-Service -Name w32time | Stop-Service
 
checking for Status

 PS C:\Users\administrator> Get-Service -Name w32time

Status   Name               DisplayName                          
------   ----               -----------                          
Stopped  w32time            Windows Time
                         


For Bulk of servers This time we are doing stopping as well Disabling the service




$computers = Get-Content C:\servers.txt

ForEach ($computer in $computers)

{

  
      Stop-Service -InputObject $(Get-Service -Computer $computer -Name w32time);
 Set-Service  -StartupType "Disabled" -InputObject $(Get-Service -Computer $computer -Name w32time);

   
}



 

Tuesday, 17 December 2013

Getting Serial number for local system and Remote systems

Friends today i have posted a new article for getting serial number for local and remote systems

Well this is very helpful for System administrators who are maintaining the Inventory.

On local system

Get-WmiObject win32_bios | Select-Object __server,serialnumber


__SERVER                                                                                    serialnumber                                                                              

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

CORESHELL                                                                                   AWCCHDNA056JJI          
 

Geeting Serial numbers for list of servers.

 
Get-WmiObject win32_bios -ComputerName (Get-Content C:\servers.txt)| Select-Object __server,Serialnumber
CORESHELL                                                                                   AWCCHDNA056JJI          
NODE1                                                                                       VMware-56 4d 56 6a 4e 70 d3 38-5e b0 01
INDDC                                                                                       VMware-56 4d 4b 6e 9f 8a 12 17-ae c6 20 02
NODE2                                                                                       VMware-56 4d 4c fa 0f 4b ef 42-2b 5e 38 9e
 
where servers.txt contains list of servernames 
 
 
 
                                                                      

Tuesday, 26 November 2013

Getting service status on Local and remote servers

If you want to know the status of Particular service on local and Remote Servers use below Powershell cmdlets

On Local
PS C:\> Get-Service -Name spooler
Status   Name               DisplayName
------   ----               -----------
Running  spooler            Print Spooler
for remote servers

 PS C:\> Get-Service -Name spooler -ComputerName INDDC
Status   Name               DisplayName
------   ----               -----------
Running  spooler            Print Spooler

Wednesday, 30 October 2013

some time system admin need to disable or change the start up type of some important services on windows.If the windows Machines  are less than 10 we can manage but what will be if the count is more than 100?


Set-Service -Name "W32Time" -StartupType "disabled" -ComputerName (Get-Content C:\Computers.txt)

where computers.txt contains list of servers which we need to disable service..

It helps in saving lot of time..


Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress

#Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress # use...