Solved

script to deploy nsclient++ agent

Posted on 2011-09-15
5
1,961 Views
Last Modified: 2012-05-12
Hello,

i need a script to install nsclient agent in 50 windows 2003-2008 servers.

the script must get a server name from txt file in this form:

server1
server2
server3
server4
....

in certain server, i have an old nsclient agent installed, so i need to uninstall it an install a new agent.

the script must do this:

if old agent exist==>

1- stop nsclient agent (agent is located in c:\nsclient), the command to stop agent is:  nsclient++.exe /stop

2-uninstall agent (agent is located in c:\nsclient)  nsclient++.exe /uninstall

3-delete c:\nsclient folder

4-copy the new folder from a network share to "c:\"

5-install the new agent from the folder (c:\nsclient) ==>nsclient++.exe /install

6-start nsclient++ service ==>nsclient++.exe /startn

i need a small report after the execution of script to coonfirm the good install of agent.

thanks for help
0
Comment
Question by:cawasaki
  • 3
  • 2
5 Comments
 

Author Comment

by:cawasaki
ID: 36543863
plz help its urgent

thanks
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 36547183
Hi Cawasaki,

This script seems pretty straightforward.  I'm going to post some code with the assumption that it might fail on your end.  If it does, please try to mess with the code to see if you can get it to work.  After you've researched the error and can't seem to produce a solution, please post back.  With that being said, here's what I've come up with as your starting skeleton.

#the script must get a server name from txt file in this form:
$Servers = Get-Content C:\Servers.txt

#in certain server, i have an old nsclient agent installed, so i need to uninstall it an install a new agent.
#This can be done with a registry check, or a simple check for the folder

#if old agent exist==>
if (Test-Path "C:\nsclient"){
#If we are in here, it means the folder exists so we have to uninstall the old version
#1- stop nsclient agent (agent is located in c:\nsclient), the command to stop agent is:  nsclient++.exe /stop
"Found old version of NSClient"
"Stopping Service..."
nsclient++.exe /stop

#2-uninstall agent (agent is located in c:\nsclient)  nsclient++.exe /uninstall
"Uninstalling NSClient..."
nsclient++.exe /uninstall

#3-delete c:\nsclient folder
"Deleting NSClient Folder..."
Remove-Item "C:\nsclient" -force
}#end removing old NSClient
#4-copy the new folder from a network share to "c:\"
"Copying NSClient Folder to C:\..."
Copy-Item "\\IP\SharedFolder\NSClientFolder" "C:\"

#5-install the new agent from the folder (c:\nsclient) ==>nsclient++.exe /install
"Installing NSClient"
c:\nsclient\nsclient++.exe /install


#6-start nsclient++ service ==>nsclient++.exe /startn
"Starting NSClient Service..."
c:\nsclient\nsclient++.exe /startn
#i need a small report after the execution of script to coonfirm the good install of agent.
$ServiceCheck = $null
$ServiceCheck = get-service "NSClient"
if ($ServiceCheck -eq $null){
"Service not found"
}
else
{
"NSClient Service Successfully installed and running"
}

###########################################################

So after all that, this script is only useful locally.  Because NSClient++.exe is a program on the remote server, if you run it remotely, it will execute locally.  Unless you use PSRemoting to do this, you're forced to make it a startup script for a client computer.  This is the recommended way to do it.  Or you can make it a logon script for your admin account and log into each server and it will run automatically.  Remember you can't make a logon script a .ps1 file without being a Server 2008 environment, so you can use a batch file to call powershell with an argument to run a script from the local computer.  Again, this is tough as each phase of the process requires more help.

I'd like to be as much help as possible, but I don't think you can do this without some research on your end.

HTH,

Dale Harris
0
 

Author Comment

by:cawasaki
ID: 36547444
Hi Dale,

The script must work remotely, so you can add fo exemple the psexec use?

thanks
0
 
LVL 16

Accepted Solution

by:
Dale Harris earned 500 total points
ID: 36549050
Well the good thing is, if you can get PS Remoting to work (http://technet.microsoft.com/en-us/magazine/ff700227.aspx), then the commands will still be the same because it will be a "native command".  So the script doesn't change except for the fact that you'll need to initiate a remote session.

So no new script, but I've messed with remoting before, and it can be a little bit frustrating at times because you also have to set it up on every client/server you want to connect to.

Here's some info on PsExec.  I haven't gone that route but this may be something you can do.

http://technet.microsoft.com/en-us/sysinternals/bb897553

Again, you're going to have to play around with this to get either way to work.  Just running a command remotely like "ipconfig" will be a challenge IMO and to get there you'll probably benefit from looking up some documentation on top of what I've already provided.

HTH,

Dale Harris
0
 

Author Closing Comment

by:cawasaki
ID: 36554671
thanks Dale, i will use PSEXEC.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now