我有两个关于powershell和IIS的问题

时间:2018-06-15 04:52:55

标签: powershell iis

我尝试将用户帐户设置为网站身份验证的匿名身份,并且我已查看了Google搜索的每个页面但未找到任何内容。有一些关于将它设置为池身份的事情,这是我得到以下行的地方,但我不确定该行是如何设置池身份的,我已经尝试修改它设置我想要的用户帐户,但它不起作用:

set-webconfigurationproperty /system.webServer/security/authentication/anonymousAuthentication -name UserName -value "domain\user" -Location "iis:\Sites\$NewApp"

我在创建网站后也尝试设置绑定,但绑定未正确应用,我无法理解原因。我在网上看了很多例子,并试图模仿他们所拥有的东西。我确定我只是有格式错误或类似的东西。这是我的约束线:

New-Item IIS:\Sites\$NewApp -bindings @{protocol="http";bindingInformation=$NewIP+":80"} -physicalPath "E:\Physicalpath"

我今晚花了2个小时,这让我发疯了。我刚刚分解并为这些几个项目手动配置服务器,但我真的想让它工作,所以我可以将它用于其他网站创建脚本。

提前感谢您的任何帮助。

1 个答案:

答案 0 :(得分:0)

我能够设置用户,需要添加-PSPath。您应该能够根据链接-PSPath-Location合并:Enable authentication for IIS app in Powershell

set-webconfigurationproperty /system.webServer/security/authentication/anonymousAuthentication -name userName -value "domain\user" -pspath iis:\ -Location "iis:\Sites\pwa"

此外,您在此处澄清了第二个疑问:Examples of IIS Powershell cmdlets

从以上链接:

  

命令示例:当IIS powershell cmdlet使用-Value参数时,它通常设置为单个字符串值(注意:如果   该值包含空格,应引用"或')

     

如果用于设置集合项

,则该值可以是哈希表对象      

附加webconfiguration   ' /system.applicationHost/sites/site [@name ="默认网站   网站"] /绑定' -value @ {protocol =" http&#34 ;; bindingInformation =" *:80:"}   -pspath iis:\

您可以使用Add-WebConfiguration来设置绑定,如下所示:

Add-WebConfiguration '/system.applicationHost/sites/site[@name="pwa"]/bindings' -Value @{protocol="ftp";bindingInformation="10.0.0.100:21:pwa.fabrikam.local"} -PSPath iis:\

或者,您可以使用Set-WebConfiguration进行修改:

set-WebConfiguration '/system.applicationHost/sites/site[@name="pwa"]/bindings' -Value @{protocol="https";bindingInformation="*:443:pwa.fabrikam.local";sslFlags=0} -PSPath iis:\

通过变量添加所有内容。您可以根据需要管理变量,我将绑定的每个组件分成各种变量。将变量放在括号内有助于评估表达式。

$siteName = "pwa"
$appFilter = "//system.applicationHost/sites/site[@name='$($sitename)']/bindings"
$newIP = "*"
$port = 80
$hostName = "pwa.fabrikam.local"
$bindings = @{
    protocol = "http"
    bindingInformation="$($newIP):$($port):$($hostName)"
}

set-WebConfiguration  -Filter $appFilter -Value $bindings -PSPath iis:\

如果您现在只更改变量,则命令应继续运行。我尝试通过变量$newIP$port更改IP和端口。让我们知道怎么回事。