我有以下脚本来创建一个正常工作的基本IIS站点
New-Website -Name "TestApp1" -Port 80 -IPAddress "192.168.1.222" -HostHeader "testapp1.example.com" -PhysicalPath C:\Powershell\TestCreateFolder1 -ApplicationPool "DefaultAppPool"
但我没有这个脚本工作
$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
我收到此错误
-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
答案 0 :(得分:1)
PowerShell命令New-WebSite $site_command
将整个$site_command
解释为网站名称。如果要将New-Website
命令用作变量,请尝试改为:
$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
请注意,New-Website
命令位于变量中,而不是从示例中的-Name
开始。