Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell “设置”;“立即启动应用程序池”;使用power shell创建应用程序池时设置用户名和密码_Powershell_Iis 8 - Fatal编程技术网

Powershell “设置”;“立即启动应用程序池”;使用power shell创建应用程序池时设置用户名和密码

Powershell “设置”;“立即启动应用程序池”;使用power shell创建应用程序池时设置用户名和密码,powershell,iis-8,Powershell,Iis 8,我正在通过powershell脚本创建应用程序池 即使环顾四周,我也找不到如何将“立即启动应用程序池”设置为true。我该怎么做 另外,如果提供了用户名/密码,那么我想设置它,否则它应该是应用程序池标识。我做得对吗 下面是函数 Function Create-AppPools($appPoolName, $appPoolDotNetVersion, $managedPipelineMode, $startMode, $userName, $password) { if(!$appPool

我正在通过powershell脚本创建应用程序池

  • 即使环顾四周,我也找不到如何将“立即启动应用程序池”设置为true。我该怎么做

  • 另外,如果提供了用户名/密码,那么我想设置它,否则它应该是应用程序池标识。我做得对吗

  • 下面是函数

    Function Create-AppPools($appPoolName, $appPoolDotNetVersion, $managedPipelineMode, $startMode, $userName, $password) {
        if(!$appPoolName){
            return;
        }
    
        Write-Host " "
    
        #navigate to the app pools root
        cd IIS:\AppPools\
    
        #check if the app pool exists
        if (!(Test-Path $appPoolName -pathType container))
        {
            Write-Host "`t Creating AppPool: " + $appPoolName
            #create the app pool
            $appPool = New-Item $appPoolName
            if($appPoolDotNetVersion){
                $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $appPoolDotNetVersion
            }
            if(@managedPipelineMode){
                $appPool | Set-ItemProperty -Name "managedPipelineMode" -Value $managedPipelineMode
            }
            if($startMode){
                $appPool | Set-ItemProperty -Name "startMode" -Value $startMode
            }
            if($userName -and $password){
                $apppool | Set-ItemProperty -Name processmodel -value @{userName = $userName;password=$password;identitytype=3}
            }
            else{
                $apppool | Set-ItemProperty -Name "ProcessModel.IdentityType" -value  3
            }
            Write-Host "`t`t AppPool: " + $appPoolName + " created successfully" -ForegroundColor Green
        }
        else{
            Write-Host "`t AppPool " + $appPoolName + " already exists" -ForegroundColor Blue
        }
    }
    
    更新1:
    在我的问题得到回答后,检查示例脚本

    您的第四个
    if()

    除此之外,您的代码工作正常。

    • 它会立即启动应用程序池。这可以通过CLI和IIS管理GUI进行验证
    • 如果用户/密码参数正确,即用户存在且密码准确,则池的标识将设置为这些参数。这可以在IIS管理GUI中进行验证
    我建议通过
    #Requires
    语句指定代码所依赖的模块

    #需要-运行管理员
    #需要-模块WebAdministration
    函数创建应用程序池(
    $appPoolName=“TestPool2”,
    $appPoolDotNetVersion=“v4.0”,
    $managedPipelineMode=“集成”,
    $startMode=“OnDemand”,
    $userName,
    $password
    ) {
    如果(!$appPoolName){
    返回;
    }
    写入主机“”
    #导航到应用程序池根目录
    cd IIS:\AppPools\
    #检查应用程序池是否存在
    if(!(测试路径$appPoolName-路径类型容器)){
    写入主机“`t正在创建AppPool:”+$appPoolName
    #创建应用程序池
    $appPool=新项目$appPoolName
    如果($appPoolDotNetVersion){
    $appPool | Set ItemProperty-名称“managedRuntimeVersion”-值$appPoolDotNetVersion
    }
    如果($managedPipelineMode){
    $appPool | Set ItemProperty-名称“managedPipelineMode”-值$managedPipelineMode
    }
    if($startMode){
    $appPool | Set ItemProperty-名称“startMode”-值$startMode
    }
    如果($userName-和$password){
    $apppool | Set ItemProperty-Name processmodel-value@{userName=$userName;password=$password;identitytype=3}
    }
    否则{
    $apppool | Set-ItemProperty-名称“ProcessModel.IdentityType”-值3
    }
    写入主机“`t`t AppPool:+$appPoolName+”已成功创建”-ForegroundColor绿色
    }
    否则{
    写入主机“`t AppPool”+$appPoolName+”已存在”-ForegroundColor蓝色
    }
    }
    创建应用程序池
    
    谢谢@derekbaker!你知道把.netClrVersion设置为无托管代码有多容易吗?@learning。。。我想您应该将
    $appPoolDotNetVersion
    参数设置为
    $null
    。为了确定这一点,我在使用该设置创建了一个池之后运行了以下代码:
    Import Module iisadmin;获取IISAPPOOL |选择对象-属性*
    。当我这样做时,它看起来是空的。对于dotNetVersion“No Managed Code”,必须传入“No Managed Code”字符串。下面是信息
    appPoolDotNetVersion=v2.0 | v4.0 |无托管代码
    appPoolManagedPipelineMode=Classic |集成
    appPoolStartMode=OnDemand |始终运行