Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

script to deploy nsclient++ agent

Posted on 2011-09-15
5
Medium Priority
?
2,156 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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