Scripting remote control for IIS 7 - iis-7

My server is running on windows server 2008, IIS 7.
My client is Windows server 2003 or Windows XP.
I want to start/stop websites remotely.
I easily managed to do it interactively using IIS 7 manager on my clients machines (cf http://blogs.iis.net/bdela/archive/2007/10/08/remote-administration-managing-iis-7-rco-from-windows-xp-2k3-and-vista.aspx )
But I want to do it in a non interactive-way, the goal is to script this as part of a msbuild script.
I tried the MSBuildExtensionPack but it works only if IIS7 is installed on the client site.
I tried powershell cmdlets, but I have to start dcom on the server (http://learn.iis.net/page.aspx/160/writing-powershell-commandlets-for-iis-70/ ).
What can I do?

If you can upgrade both client and server to PowerShell 2.0 you could use PowerShell remoting along with PowerShell 2.0's WebAdministration module to do this. First you need to enable remoting on the server PowerShell like so (from an elevated prompt):
PS> Set-ExecutionPolicy RemoteSigned
PS> Enable-PSRemoting -Force
Then on the client machine execute the following:
PS> Invoke-Command servername {Import-Module WebAdministration; Stop-WebSite Foo}

Thanks! Powershell 2.0 did the trick. Nevertheless your commands didn't seem to work.
On the server side I ran
PS> winrm quickconfig
and on the client side I ran
PS> Invoke-Command -computername servername -scriptblock {[system.reflection.assembly]::loadfrom("c:\windows\system32\inetsrv\microsoft.web.administration.dll");$server2 = New-object microsoft.web.administration.servermanager;$server2.Sites["Foo"].Stop()}
As described in : http://www.powershellcommunity.org/Default.aspx?tabid=55&EntryID=65

Related

ASP.Net Webforms, run Powershell script on more than 200 Windows 10 machines where firewall is enabled

I need to Change Service user, Start and Stop Windows Services through PowerShell. I am invoking the PowerShell script from an ASP.Net Webforms.
All 200 Windows 10 machines are firewall enabled. I am using following Powershell code segment to change user:
$oService = Get-WmiObject -ComputerName $Server -Query "SELECT * FROM Win32_Service WHERE Name = '$sServiceName'"
$oService.StopService() | Out-Null
$oService = Get-WmiObject -ComputerName $Server -Query "SELECT * FROM Win32_Service WHERE Name = '$sServiceName'"
$oService.Change($null,$null,$null,$null,$null,$null,"$sUsername",$sPassword) | Out-Null
When the firewall is turned on then the script throws exception for each machine.
I tried to run following command on each machines:
netsh advfirewall firewall set rule group="Windows Management Instrumentation (WMI)" new enable=yes
But still no luck. Is there any way to run Powershell scripts from Asp.Net Webforms where firewall is on for each machines?

How to configure jboss-eap 6.2 as a service and set Auto-start on CentOS 6.x and Linux1 AMI

We were using an older version of Jboss 4.x with JDK 5 on CentOS 5.x, this version of Jboss is very old now, even this version is also not supported by RedHat now.
Now we are upgrading to jboss-eap 6.2 and jdk1.7.0_60 and CentOS 6.x in UAT and AWS Linux1 AMI for Production, I have installed Jboss 6.2 in /var/lib/jboss-eap-6.2 folder. Necessary modification in the code are already done, application is working fine and Jboss is running as a process using below command.
./standalone.sh -c standalone-full.xml -b 0.0.0.0 -bmanagement 0.0.0.0
Below command shows that process is running on port 8080.
netstat -aptn | grep LISTEN
Please help configure Jboss 6.2 as a service and set Auto-start, when OS starts?
Follow the below steps to Configure Jboss6.2 as Service and configure it as Auto restart. The process is same for CentOS 6.x and AWS Linux1 AMI.
Copy files into system directories
a. Copy the modified configuration file to the /etc/jboss-as directory.
mkdir /etc/jboss-as
cp /var/lib/jboss-eap-6.2/bin/init.d/jboss-as.conf /etc/jboss-as/
Uncomment following line
JBOSS_USER=root
and add the following line at the end of this file.
export JBOSS_USER
b. Copy the start-up script to the /etc/init.d directory.
cp /var/lib/jboss-eap-6.2/bin/init.d/jboss-as-standalone.sh /etc/init.d/jboss-62
Do following changes in /etc/init.d/jboss-62 file
i)-Set Java Home JAVA_HOME=/usr/java/jdk1.7.0_60 export JAVA_HOME
ii)-Set JBOSS Home JBOSS_HOME=/var/lib/jboss-eap-6.2 export JBOSS_HOME
iii)-Change Configuration xml file name(you may give what ever configuration file name you are using)
JBOSS_CONFIG=standalone-full.xml
iv)-Add "-b 0.0.0.0 -bmanagement 0.0.0.0" in the following line, so that binding is set for every IP address on this system
daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1
JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -b 0.0.0.0 -bmanagement
0.0.0.0 -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
Add the start-up script as a service.
Add the new jboss-as-standalone.sh ( i.e jboss-62 ) service to list of automatically started services, using the chkconfig command.
chkconfig --add jboss-62
Start the service.
service jboss-62 start
Make the service to start automatically when you restart your
server.
chkconfig jboss-62 on
Restart the service
service jboss-62 restart
Now Jboss6.2 configuration as a Service as Auto restart is complete.
Reboot os and check that service is running. Run below command ot verify that service is running on port 8080
netstat -aptn | grep LISTEN | grep 8080

Jython When dmgr is down, how can we restart the application

on my server dmgr is down, how can I stop/start the application running on server1?
wsadmin script throwing exception.
Thanks
SF
Use the -host and -port options of wsadmin to point to server1.
Alternatively, restart the dmgr.
If servers is federated, we can't connect to server directly. we need dmgr and nodeagent running to stop/start only application.
or
Server has to be standalone.
Thanks
-SR

Powershell remote install .exe file errors and not finding setup.iss file

Hi I am trying to figure out how to install .exe files to 5 server machine but I am having trouble trying to install silently on my own machine.
I have this command
Invoke-Command -ScriptBlock {Start-Process -FilePath \\xxx-STUDENT3-W7\Users\bkoo004\Documents\test\ccleaner402.exe \r}
but I can't find the setup.iss file in the Windows folder.
Also when I use this command
Invoke-Command -computername xxxxxxxxxxx.edu -ScriptBlock {start-process -filepath "\\xxx-S
TUDENT3-W7\Users\bkoo004\Documents\test\ccleaner402.exe" } -Credential $cred
It gives me an error saying that
This command cannot be executed due to the error: The network name cannot be found.
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
But I know that network name is right because when I run
Invoke-Command -computername xxxxxxxxxxx.edu -ScriptBlock {get-process } -Credential $cred
It returns the get-process of that server.
I figured that for not getting the setup.iss file it is because the program that i am trying to install doesn't use installshield but for the error trying to run start-process on my remote server I have no idea what it is.
Not sure if you are running into the double-hop problem on not, but it sounds like you are. So I though I'd give you a little more information about it. The Bob Loblaw version.
What is a server and what is a client? A server, it accepts things, is the computer you remote onto. A client, it gives things, is the computer you use to do the remoting. So in the command Invoke-Command -computername xxxxxxxxxxx.edu ..., "xxxxxxxxxxx.edu" is the server.
From your description, it looks like you already ran the command Enable-PSRemoting on your server. With remoting enabled on the server you should be able to do Enter-PSSession -ComputerName xxxxxxxxxxx.edu and have an interactive command prompt on the client.
If you enter a remote session and do Get-ChildItem "\\ComputerName\Share" the command is going to fail (it fails for safety reasons). That's the double-hop, because you're going from one computer to another. The network share is another computer. So you're going like this:
Client -> Server -> Network Share
Hippity-Hoppity
You need to setup more "things" to fix the double-hop. First on your server(s) you need to run the command Enable-WSManCredSSP Server so it will accept credentials from clients. Second on your client(s) you need to run the command Enable-WSManCred -Role Client -DelegateComputer * so it gives out your credential to servers.
Now with CredSSP configured to give and accept credentials, you should have resolved the doulbe-hop.
Enter-PSSession -ComputerName Computer1 -Authentication Credssp -Credential (Get-Credential)
Now you should be able to get to your network shares from the remote session Get-ChildItem "\\ComputerName\Share".
Hope this helps you out a bit.
P.S. There is always money in the banana stand.

About GlassFish Running

I try to run an EJB example using NetBeans IDE and GlassFish Server v3. When I run my client code(The class that have main method), I faced this Error:
Starting GlassFish Server 3.1.2
GlassFish Server 3.1.2 Server cannot start. Port is occupied.
C:\Users\7\Documents\NetBeansProjects\MDbexample\nbproject\build-impl.xml:907: Deployment error: GlassFish Server 3.1.2 Server cannot start. Port is occupied.
So I decided to run GlassFish by using command line:
c:\glassfish3\bin>asadmin start-domain
Now I faced this massage on cmd environment:
There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server.
Command start-domain failed.
Is there anybody that know How I can solve my problem?
Thanks in advance.
insert line into /etc/hosts say;
<HOSTNAME> <REALIP>
myMachine 10.102.55.45

Resources