Error using appcmd to add ssl binding - iis

I want to add a binding to a site using appcmd. But when I try the following command I get an error:
appcmd set site /site.name:"My site name" /+bindings.[protocol='https',bindingInformation='*:443:sub.mydomain.com']
The error:
ERROR ( message:Cannot find SITE object with identifier "bindingInformation='*:443:sub.mydomain.com']". )
I checked if the site exists and it does. What am I doing wrong?

If you're using PowerShell, you have to surround the bindings parameter with double quotes so that PowerShell doesn't interpret the single quotes before the command is sent to appcmd.
./appcmd set site /site.name: contoso /+"bindings.[protocol='https',bindingInformation='*:443:']"
source: http://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx

Try this:
appcmd set site "My site name" /bindings:"https://sub.mydomain.com:443"
But your command is correct as well. List all websites and make sure you are using one of them:
appcmd list site

I ran into a problem in Powershell with the colons in the bindings. Concatenating them solved the issue.
[string] $cmd = "$Env:windir\SysWOW64\inetsrv\APPCMD.exe"
$response = invoke-expression "$cmd add site /name:""$SiteName"" /id:$ID /+""bindings.[protocol='$Protocol',bindingInformation='$IP"+":$Port"+":']"" /physicalPath:""$Path"""

You need to run your command as administrator.

I was never able to make this work with a wildcard certificate for *.mydomain.com with what I thought to be a quite friendly name: "mydomain.com plus wildcard". I'd run the commands above, go into IIS and look at the bindings and it would be there but without a certificate selected. Selecting the certificate would removed the host name and disable it so I couldn't change it.
I finally got it to work by changing the wildcard certificate's friendly name to the format expected by IIS ("*.mydomain.com") and adding it normally through the IIS interface, no idea if the above appcmd commands would work. The moral of this story is to give wildcard certs the standard form friendly name.

I created a batch file to achieve that:
#echo off
set /p sitename="Enter the site Name (as displayed in IIS): " %=%
set /p siteurl="Enter the site Host Header(the site url): " %=%
set /p siteip="Enter the site IP Address (ip address or *): " %=%
set /p siteprotocol="Enter the site Protocol (http, https, etc): " %=%
set /p siteport="Enter the site Port (80, 443): " %=%
appcmd set site /site.name:"%sitename%" /+bindings.[protocol='%siteprotocol%',bindingInformation='%siteip%:%siteport%:%siteurl%']
pause

Related

APPCMD how to test if binding exists before I add it to a website?

We use appcmd in our deployment scripts to setup servers , I need to ensure that adding bindings to existing sites doesn't throw an error
C:\Windows\System32\inetsrv\appcmd.exe set site /site.name:"abc.com"
/+bindings. [protocol='http',bindingInformation='*:80:alias-abc.com']
works but in the next script run I get the error ..
cannot add duplicate collection entry of type 'binding' with combined key attribuites 'protocol, bindingInformation' respectively set to '
http, *:alias-abc.com'
Is there a way I can check if the binding exists before adding it in appcmd
(powershell is not allowed - so has to be either appcmd or other command line exe)
Thanks
appcmd is a bit lacking in the search department, but something like this should work:
C:\Windows\system32\inetsrv\appcmd.exe list site "abc.com" | findstr bindings:http/*:80

How do I modify the Site Collection in SharePoint 2013?

When I try to open a form published from InfoPath I now get this error:
"The following location is not accessible, because it is in a different site collection:
https//portal/sites/forms/Daily%20Activity/Forms/template.xsn?SaveLocation=https//portal.alamedacountyfire.org/sites/forms/Daily%20Activity/&Source=https//portal.alamedacountyfire.org/sites/forms/Daily%2520Activity/Forms/AllItems.aspx&ClientInstalled=false&OpenIn=Browser&NoRedirect=true&XsnLocation=https//PORTAL/sites/forms/Daily%20Activity/Forms/template.xsn."
Correlation ID:12c0ab9c-caff-80a8-f1b4-64d81dcfa6ea
Following are some options that you can try:
1) Save the form template (.xsn) as the source files in the publish options. Look at the manifest file in notepad and see if you can find a reference to the incorrect location. If so, correct it and Republish the form.
2) Clear the InfoPath cache on that machine. Start->Run "infopath /cache clearall"
3) See if the site collection has a managed path, if so, give the proper url while publishing. The XSN might be getting deployed on the root site and throws error since the intended list does'nt exist.
I found this worked for me. Got the answer from another post.
"I had a similar problem and found it was due to the request management service routing from my web application host header to the server name.
There was a routing rule in my request management settings. I just disabled routing and the problem went away. I used the following powershell to disable it. "
$w = Get-SPWebApplication "http://webapphostname"
$r = $w | Get-SPRequestManagementSettings
$r.RoutingEnabled = $false
$r.Update()
You may want to configure it rather than disable it. Here’s a good resource to get you started:
http://www.harbar.net/articles/sp2013rm1.aspx

Powershell Start-Website IIS

Problem/Question
I'm test running a script for redgate deployment. At the last step it starts a website:
import-module WebAdministration
$website = get-website | where-object { $_.name -eq $RedGateWebSiteName }
#(re)write HostName#
$binding = Get-WebBinding -Name $RedGateWebSiteName
Set-WebBinding -Name $RedGateWebSiteName -BindingInformation "*:80:*" -PropertyName HostHeader -Value $HostName
if ($website) {
Start-Website "$RedGateWebSiteName"
}
It always worked but now on one of the last days I get this error
At D:\inetpub\Timeblockr-RedGate\Api\PostDeploy.ps1:15 char:15
+ Start-Website <<<< "$RedGateWebSiteName"
+ CategoryInfo : InvalidOperation: (:) [Start-Website], COMException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand
IIS error
The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://*:80/ for site 3. The necessary network binding may already be in use. The site has been disabled. The data field contains the error number.
This SO question "Cannot create a file" error when running Start-Website command in Powershell gives a pretty good clue what it can be.
Edit:
After viewing my event log and checking out the answers I found out that when Redgate automaticly tries to install/start the website i'm getting this IIS error:
The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://*:80/ for site 3. The necessary network binding may already be in use. The site has been disabled. The data field contains the error number.
In this Serverfault : https://serverfault.com/questions/456217/the-world-wide-web-publishing-service-www-service-did-not-register-the-url someone its mentioning that the cause of that is that a IIS website gets created without hostheader. I'm adding the hostheader after I try to start the website. Lets find the solution
Edit 2:
I was adding the hostname after I tried to start the website. This caused that the website has e empty hostname and that conflicts in IIS. (or somewhere else).
I've changed my script to get the website, add the hostname and then start the website.
Also added "$RedgateWebsiteName" instead of $RedGateWebSiteName. Works perfectly now!
Edit 3:
After a run of tests I seem to end up the same error. The one deploy has no problems, the other deploy does has.
Edit 4:
I've updated the script / Error / Post.
I deleted my site from IIS after that I clicked on install. Perfectly installed - No problems, automatic start.
Second run exactly the same, third run I get the error above!
I'm guessing the $RedGateWebSiteName variable had not been assigned a value, assuming the log message replaces the variable with its' value. From googling around, it looks like the IIS "file already exists" message may be erroneous as it happens because of anything from a missing IP address binding to an invalid virtual directory folder.
Why do you need a script to start the website? If you are using Red Gate Deployment Manager, it starts the website after the deploying a web package (any package with a web.config file it).
It could be that the value substitution for $RedGateWebSiteName is not taking place and it probably needs double quotes:
Start-Website "$RedGateWebSiteName"
I say this because your error message says this:
Start-Website <<<< $RedGateWebSiteName
while the error message here displays the substituted value:
start-website <<<< "MyWebsite"
I had the exact same problem, when starting the website with:
Start-Website -Name MyWebSiteName
and it would not start. When I tried to start it manually in IIS Manager, it wouldn't start either and I got this error message:
The World Wide Web Publishing Service (W3SVC) is stopped. Websites cannot be started unless the World Wide Web Publishing Service (W3SVC) is running.
This is pretty clear that the service is not started and it turned out to be true.

IIS6 bat file - Home Directory

How do I get the Root/Home Directory of a website in IIS6 using a batch file??
My Scenario:
I am creating a tool to summarise and report of sites in IIS. I am using batch files and running iisweb /query to get all the sites then looping over the results and using iisvdir /query "Website Name" to get the virtual directories.
However it has to be backwards compatible with IIS6 and I am having trouble getting the Home Directory of the site.
I don't think you can do this directly from a batch file, but you should be able to do it from a vbscript which you can call from a batch file.
The trick is to use the IIS WMI provider which gives you access to the IIS metabase. For example, the script below should echo the name and path of every virtual directory on the local server.
set provider = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
set results = provider.ExecQuery("SELECT Name,Path from IISWebVirtualDirSetting")
for each item in results
WScript.Echo item.Name
WScript.Echo item.Path
next
If you saved this script as iispaths.vbs (just as an example), you could then call it from a batch file with:
cscript //nologo iispaths.vbs
Unfortunately I don't have access to a machine with IIS6, so I am unable to test this at the moment, but if you have any problems getting it to work, feel free to let me know in the comments and I'll do my best to fix the issue.
I don't have a IIS6 server, however, through some searching, I found that:
IIS6 uses %SystemRoot%\system32\inetsrv\MetaBase.xml and %SystemRoot%\system32\inetsrv\MBSchema.xml for storing configuration (The IIS Metabase (IIS 6.0));
If your server isn't changing home-directories too often, those xml should be updated;
using a command line parser (like xmlstartlet), you can extract Path property from IIsWebVirtualDir node (according Metabase Structure), using XPath.
With xmlstartlet, a command like below, would output root path:
xml sel -t -v "//IIsWebVirtualDir[#Location='/LM/W3SVC/1/ROOT']/#Path" "%SystemRoot%\system32\inetsrv\MetaBase.xml"
Maybe schema needs to be corrected.
This can be a command line approach. I can't test it as I don't have any IIS6 server neither I can get any MetaBase.xml sample.

Associate an application pool to site with appcmd

I want create a site by command line using appcmd.
How can I associate a specific application pool to site?
To create a site, I write in this way:
appcmd add site /name:"prova" bindings:http://localhost:8080 /physicalPath:c:\sites\prova
You can do this:
APPCMD.exe set app "prova/" /applicationPool:"YOUR_APP_POOL_NAME_HERE"
Note the trailing slash appended to prova, that's important.
For example if I wish to set the application pool for prova to the DefaultAppPool I would issue the following command:
APPCMD.exe set app "prova/" /applicationPool:"DefaultAppPool"
Picking up from Chris's comment below, if you have an existing application in your site, say /mybloggy and you wish to change application pool it belongs to then you'd issue the following:
APPCMD.exe set app "prova/mybloggy" /applicationPool:"DefaultAppPool"
Alternative syntax:
APPCMD.exe set site /site.name:"Site name" /[path='/'].applicationPool:"App Pool Name"
Found in Windows Server docs:
https://technet.microsoft.com/en-us/library/cc732992(v=ws.10).aspx
Although the OP was looking to assign the app pool within the "add site" command, I couldn't find a way to include it with the original "add site" command. I got it working using "add site" followed by "set site" using syntax by Kev above.
On the other hand, if you ever need to add an "application" under that "site", you can specify the app pool when you use the "add app" command with the applicationPool argument as here:
APPCMD add app /site.name:"prova" /path:/App1 /physicalPath:c:\sites\prova\App1 /applicationPool:"provaAppPool"
p.s. You may need to prefix APPCMD with %systemroot%\system32\inetsrv\ and call
%systemroot%\system32\inetsrv\APPCMD /site.name:"prova"...

Resources