Reputation: 2547
I have following script to create an basic IIS site which is working
New-Website -Name "TestApp1" -Port 80 -IPAddress "192.168.1.222" -HostHeader "testapp1.example.com" -PhysicalPath C:\Powershell\TestCreateFolder1 -ApplicationPool "DefaultAppPool"
But I dont have this script working
$site_command = "-Name ""TestApp1"" -Port 80 -IPAddress ""192.168.1.222"" -HostHeader ""testapp1.example.com"" -PhysicalPath C:\Powershell\TestCreateFolder1 -ApplicationPool ""DefaultAppPool"""
New-WebSite $site_command
I am getting this error
-Name "TestApp1" -Port 80 -IPAddress "192.168.1.222" -H
ershell\TestCreateFolder1 -ApplicationPool "DefaultAppP
New-Website : Invalid site name
At C:\powershell\CreateIisSite.ps1:35 char:12
+ New-WebSite <<<< $site_command
+ CategoryInfo : InvalidData: (:) [New-Web
+ FullyQualifiedErrorId : Invalid site name
,Microsoft.IIs.PowerShell.Provider.NewWebsiteCommand
Upvotes: 0
Views: 742
Reputation: 1240
The PowerShell command New-WebSite $site_command
is interpreting the entire $site_command
as the name of the website. If you want to use your New-Website
command as a variable, then try this instead:
$site_command = "New-Website -Name ""TestApp1"" -Port 80 -IPAddress ""192.168.1.222"" -HostHeader ""testapp1.example.com"" -PhysicalPath ""C:\Powershell\TestCreateFolder1"" -ApplicationPool ""DefaultAppPool"""
Invoke-Expression $site_command
Note that the New-Website
command is in the variable, instead of starting at -Name
in your example.
Upvotes: 2