About Me


Name: Ali Hassan
Location: Dubai (UAE)




Fun with Powershell - Stopping services remotely

Powershell is something can you get addicted to very fast, if you know what  you are doing! So this morning I was messing around with the "read-host" cmdlet and I wanted to try something with services. I wanted to ask the user what service he/she wanted to restart and on what computer. After that I wanted to go ahead and restart that service, assuming you have the privileges on the remote machine and then display a status message. Its not a ground breaking script but something to do for fun! (Well, don't go about restarting services in your production environment now, just coz I have mentioned the "fun" bit!)

You can extend the below script by checking if the user has entered a valid service name or a valid computer name and if not you can display a warning message. I leave that part to you and if you do extend it, please comment below and let me know!

$service = read-host "What is the service you want to STOP?"
$computer = read-host "What is the server name you want to STOP this service on?"
Get-Service $service -ComputerName $computer | Stop-Service -Force
Get-Service $service -ComputerName $computer
$svc = Get-Service -ComputerName $computer -Name $service
write-host "`n"
if ($svc.Status -eq "Stopped"){
Write-Host "Looks like you have stopped the service, using the $env:userdomain\$env:username account" -ForegroundColor Green
write-host "SORRY, the service could not be stopped :-("

Fun with Powershell - How to change the server DNS and GATEWAY remotely using Powershell

I have started to indulge myself with Powershell lately and this is a pretty handy script that I came up with, I wanted to change the dns servers and the gateway for some of my test servers remotely, so I was looking at how I could do it with my new found abilities!

Its a pretty simple script, nothing fancy and I am sure there are similar ones on the internet! So here goes..

$servers =  Get-Content -Path C:\Mobaterm\repo\servers.txt
$dnsservers = "",""
$gateway = ""
$nics = Get-WmiObject win32_networkadapterconfiguration -ComputerName $servers -Filter "ipenabled = true"
foreach ($nic in $nics){

As you can see above, I have stored my server list in a file called servers.txt and called that in a variable called $servers. Then I create different variable for the dns servers that I want to modify with the ip addresses and a new variable for the gateway.

Then I retrieve the active network card information using a WMI class and start a for loop to iterate through each item and modify it. Like I said pretty simple nothing out of the ordinary.



Configuring Ansible for Centos

Ok then, for  the past few months I have been trying to get my Linux skills up to speed so that I can get involved in the technology. My present work has nothing to do with Linux and in all likelihood what I learn in terms of Linux will never be helpful in what I do. However it might be helpful in life! (ahh so philosophical!)

So after going about learning a bunch of videos at Linux Academy, which I completely recommend by the way, I wanted to get into the world of Ansible. Why you may ask? Well its just plain fun (such a geek!). So I initially tried to get Ansible to work with Windows and winrm and I failed miserably! I spent like 2 whole days I couldn't get it to work, so I just gave up on the Windows bit and concentrated on managing the Linux boxes!

So in  this post I will try to outline the steps I did to get Anisble working in my lab with mainly Centos boxes!


Control Server

Machine name: Oracle

OS: CentOS

Remote Hosts

Machine Names: Neo, Trinity and Morpheus

OS: CentOS

Installing ansible on the control server (Oracle)

I am logged in as root and I will run the setup using this account


# yum update && yum upgrade -y

Install wget

# yum install wget

Since this is CentOS we need to download the repo and install it from that.

# wget
# rpm -ivh epel-release-latest-7.noarch.rpm

# yum install epel-release

Install Python and misc tools

# yum install python

# yum install python-pip

# pip install --upgrade pip

# pip install markupsafe

# pip install xmltodict

# pip install pywinrm

Install Ansible

# yum install ansible -y

Confirm the installation

# ansible --version

you should see something like

config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

ansible  config file = /etc/ansible/ansible.cfg  configured module search path = Default w/o overrides



Another things you would need to do is setup SSH key based authentication to the remote hosts from your control server. .

The SSH Key based authentication is really easy to setup, All you need to do is on the control server issue the below commands.

 # ssh-keygen -t rsa

# Enter the file in which to save the key (Press enter to accept the default location)

# Enter a passphrase (You can choose to leave it blank if this is a test environment or else enter something in)

After the key has been created with a conformation screen you need to copy this key to all the remote hosts that you plan to manage using the below command.

# ssh-copy-id root@neo

Type yes on the next prompt and then eventually enter a password for the remote machine to get the keys copied over. After the keys have been copied perform a SSH to the remote machine and this time it should ask you for the pass phrase and once you enter that it will let you in.



Error ndmpagent (pid=6536) ndmp_data_connect_v3 failed, status = -1

While backing up my NDMP share I kept getting an annoying message and the backups were failing, everything was configured fine in my Netbackup 8 console but the error still persisted with the below message.


All I had to do is open up the firewall ports on the Windows server and the backup started working, so in case you see the same message try opening up the firewall ports and re-run the backup.



Vsphere web client service crashes after upgrading to Update 3 

Today I ran into a minor issue when I upgraded my Vcentre and all the components to Update 3. My web client service would just crash on me even if I started it manually. So here is what I did to fix that.

  1. Stop the vSphere Web Client Service. 
  2. Move the WORK folder from this location. (DO NOT DELETE THE FOLDER)
    C:\Program Files\VMware\Infrastructure\vSphereWebClient\server\work
  3. Start the vSphere Web Client Service.