How to find the system uptime in Windows XP/2003/Vista/2008

February 6th, 2012 No comments

There are two ways to find the system uptime in Windows XP and above:

Using Systeminfo command:

This command-line utility shows the time that the system was booted and its running time.

To use  Systeminfo,

  • launch the command prompt “cmd” window (Start – Run, cmd) .
  • From the command prompt, type “systeminfo“ and hit enter. This will display various system info including the “System boot time”:

 

Using “net statistics” command

From the command prompt run, the following command:

net statistics workstation

This will  show the system statistics:

 

Categories: cmd, Commands Tags:

Killing a stuck Windows Service

December 27th, 2011 No comments

Hi

I guess all of us met the phenomenon when a service refuses to stop and stuck on ”Stopping” status.

well, there is a remedy to this by following this short procedure:

1. Identify the PID of the rogue service. open cmd and type: sc queryex

you will receive a long list of available services. you can also type sc queryex > c:\ServiceList.txt to send the output to a text file.

2. search the list of services for the problematic service:

SERVICE_NAME: Spooler
DISPLAY_NAME: Print Spooler
        TYPE               : 110  WIN32_OWN_PROCESS (interactive)
        STATE              : 3  STOP_PENDING 

       (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0×0)
        SERVICE_EXIT_CODE  : 0  (0×0)
        CHECKPOINT         : 0×0
        WAIT_HINT          : 0×0
        PID                : 1800
        FLAGS              :

After you identified the service on the SERVICE_NAME line, notice the PID. you will need this number.

3. Using taskkill command, you can kill the rogue service now by typing: taskkill /PID 1800 /F

C:\>taskkill /PID 1800 /F
SUCCESS: The process with PID 1800 has been terminated.

 

Categories: Uncategorized Tags:

How to get a remote servers’ TCP/IP configuration: IP, DNS, GW via PowerShell

November 30th, 2011 No comments

Hello again

Sometimes I need to know the DNS configurations of a remote machine without logging in to that machine.

This nice script will do the work. The source I found on this web site and changed it for my needs.

 

$Computer = Read-Host Please Enter Host name
  Get-WMIObject Win32_NetworkAdapterConfiguration -Computername $Computer | `
  Where-Object {$_.IPEnabled -match "True"} | `
  Select-Object -property DNSHostName,ServiceName,@{N="DNSServerSearchOrder";
              E={"$($_.DNSServerSearchOrder)"}},
              @{N='IPAddress';E={$_.IPAddress}},
              @{N='DefaultIPGateway';E={$_.DefaultIPGateway}} | FT

 

 

If the DNSServerSearchOrder obscures some of the data, you can drop the “| FT” at the end of the script to get this output:



			
Categories: Powershell Tags:

Display computer name under My computer icon

November 8th, 2011 No comments

Hi

A very useful trick that I always use in my servers is displaying the computer name under ‘My Computer’ or ‘Computer’ in Windows 7/2008R2

To do this you need to change a certain registry key.

In xp/2003 operation systems the process is simple as described below.

In 2008/Win7 though, you will first have to logon as administrator and take ownership on the hive where the registry settings needs to be modified.

So how do we do this?

first open the registry editor via regedit. then go to:

HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}

find a REG_EXPAND_SZ string value names ’LocalizedString’ and change its value data to:

%computername%

Now you should see the machine name under ‘My Computer’ icon.

you can find a .reg file that does the job for you here

 The outcome for a computer named SRV000 will be this:

 

Categories: Registry Tags:

Monitoring memory usage with powershell

August 24th, 2011 No comments

Hi

Recently I discovered that some of my managed servers has a memory leak.

to find which of the 300+ servers are running out of memory,

I wrote a simple and useful powershell script.

You can use this as a template and add more hardware or software sampling with the correct WMI classes.

 

$ErrorActionPreference = “silentlycontinue”

$a = Get-Content “C:\Scripting\servelist.txt”
foreach ($_ in $a)
    {
Write-Host Monitoring $_
try
 {
        $TotMem = ((gwmi -Class win32_operatingsystem -computername $_).TotalVisibleMemorySize)/1kb
        $FreeMem = ((gwmi -class win32_operatingsystem -computername $_).FreePhysicalMemory)/1kb
        $TotFreeP = ($FreeMem/$TotMem)*100
        $TotFree = “{0:N2}” -f $TotFreeP

if ($TotFreeP -lt 20) 
    {Write-Host server $_ has $totfree% of free memory }

# or you can send the results to a file with this line: {Write-Output  ”server $_ has $totfree% of free memory ” | Out-File -append C:\Scripting\Results.txt }
 

catch
   { 
    Write-Host Error monitoring server $_ 
   }
}        
    

Categories: Commands, Powershell Tags:

Pinging multiple devices with powershell using the Test-Connection cmdlet

August 15th, 2011 No comments

Sometimes you want to know if the server, switch and workstations of a branch office are working.

Here is a simple script in Powershell that check if a computer on your network is ‘alive’ and then returns a reply: ”computer is reachable”

If not, it will return “computer is not reachable”.

Save this script as psping.ps1 and run: psping YourServerName

param ($comp)
if (Test-Connection -ComputerName $comp -Count 1 -Delay 10 -TimeToLive 10 -Quiet)
{Write-Host -ForegroundColor green “$comp is reachable”}
else {Write-Host -ForegroundColor red “$comp is not reachable”}

$switch = “sw” + $comp

if (Test-Connection -ComputerName $switch -Count 1 -Delay 10 -TimeToLive 10 -Quiet)
{Write-Host -ForegroundColor green “$switch is reachable”}
else {Write-Host -ForegroundColor red “$switch is not reachable”}

 

 

 

How to build a simple setup program you’ve developed yourself.

August 11th, 2011 No comments

Ever wanted to build your own executable software? or protect your credentials included in a script?

There are some tools on the market like ‘wise installation system’ that can do the job.

But there is also a nice and free solution from Microsoft, embedded in your OS.

 

IExpress is a wizard that builds a simple setup program for software you’ve developed yourself.

You have to provide one or more files that make up your application,

and a configuration file that describes where these files are to be copied on the target

computer. Additionally you can define Registry entries that are to be made, and you

can designate a program or script that is to be run after the files are copied onto a target

computer to complete the installation.

IExpress then compresses all of this into a single executable (.EXE) file that you can distribute and run on other computers.

 

continue with the wizard…

Select what program or script you want to run.

Choose the file you want to run.

Save your .exe program file.

 

Categories: Sysadmin Tags:

How to creat Mini Macros with the doskey command

August 10th, 2011 No comments

 

While you are in a command prompt session, you can create mini macros to execute long sentences of commands with just one word:

doskey mnd = net use Z: \\server1\myshare /user:admin MyPassword 

When you write mnd and hit enter, the complete net use command will be executed.

Categories: Commands Tags:

Welcome, IT admins

July 20th, 2011 No comments

Hi

This is my blog

I will try to share some interesting problems, hopefully with solutions that I encounter on my daily work.

I hope you enjoy your stay and come back for more.

Categories: Uncategorized Tags: