Solved

script to deploy nsclient++ agent

Posted on 2011-09-15
5
2,096 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 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