Solved

script to deploy nsclient++ agent

Posted on 2011-09-15
5
2,033 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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