Wednesday, September 21, 2016

Managing a Windows Service using PS


Administrators can control all Windows Services in their domain using PowerShell.

Get-Service is the most common cmdlet.

The basic Get-Service with no parameters shows all services on the local computer.

But most administrators will need to find services on remote computers. This can be done with the ComputerName parameter

Get-Service -ComputerName Sathees-PC

Multiple Computers

What if you want to see the services on multiple computers? Powershell has a cmdlet Get-Content that can read a text file which has computers names and by using a foreach loop, we can run Get-Service for each of those computers names.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_}

Changing a Computer's Service with PS

Let's get a little deeper and change some of the services. For example, let's start the Application Layer Gateway service on all computers in that text file. By specifying a particular service to find and then piping that object to Restart-Service.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_ -Name ALG | Restart Service}

Hope, You will not get any Red text from PS output.

The output can be viewed using below command.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_ -Name ALG}

Ref link: here

Thursday, May 12, 2016

Ways to identify a Virtual Machine

01. Using MSINFO32

Open Run Command and type in msinfo32, The System Model from list specifies whether a Machine is VM or Physical.

If its VM then the value will be 

System Model : Virtual Machine 

If its Physical then the value will be

System Model : Manufacture Model Name

02. Using Powershell Script

Run the below Powershell command from elevated permission

Systeminfo | findstr /i model

Thursday, May 5, 2016

Identifying Hyper-V Virtual Host of a VM

Recently I came across to manage the Virtual Space for the VMs which are running out of space. I had to identify Virtual Host's free space before trying to expand the VHD size as Hyper-V allows to expand it.

You can identify the Hyper-V host name in the guest VM's Registry at the following key:

HKLM\Software\Microsoft\Virtual Machine\Guest\Parameters

Dword HostName should reflect your Hyper-V Host Name where the VM is hosted.

If you feel lazy to get deep into Registry, run the below command from Powershell (I prefer Run as administrator). It works on Windows Server 2008 and higher

PS C:\Windows\System32> (get-item "HKLM:\Software\Microsoft\Virtual Machines\Guest\Parameters").GetValue("HostName")

Wednesday, May 4, 2016

It's me


I am writing this, because I need a change in my regular life
I am writing this, because I am a lazy person that I want to get rid-off
I am writing this, because I want to come out of something which I liked so much
I am writing this, because I want to forget which keeps me floating away from the normal life
I am writing this, because I want to learn writing and speaking
I am writing this, because I am confused. :)