check sharepoint server is standalone or farm mode

#-----------------------------------------------------------------------------------
# <summary>
# Check the SUT server installation mode.
# </summary>
# <param name="sutVersion">The sut server version.
# Note:its value is gotton by calling function "GetSharePointServerVersion"</param>
# <param name="computerName">The computer name of the server.</param>
# <param name="userName">The user name of the server, must be in the format DOMAIN\User_Alias.</param>
# <param name="password">The password of the user name.</param>
# <returns>
# A string value, true if the server installation mode is StandAlone, otherwise false.
# </returns>
#-----------------------------------------------------------------------------------
function CheckServerInstallationMode
{
    param(
 [String]$sutVersion,
    [String]$computerName,
    [String]$userName,
    [String]$password
    )
   
    #----------------------------------------------------------------------------
    # Parameter validation
    #----------------------------------------------------------------------------
 if($sutVersion -eq $null -or $sutVersion -eq "")
    {
     Throw "Parameter sutVersion cannot be empty."
    }
    if($computerName -eq $null -or $computerName -eq "")
    {
     Throw "Parameter computerName cannot be empty."
    }
    if($userName -eq $null -or $userName -eq "")
    {
     Throw "Parameter userName cannot be empty."
    }
    if($password -eq $null -or $password -eq "")
    {
     Throw "Parameter password cannot be empty."
    }
   
 switch($sutVersion)
    {
     {$_ -eq "WindowsSharePointServices3" -or $_ -eq "SharePointServer2007"} {$sutShortVersion = "12.0"; break}
     {$_ -eq "SharePointFoundation2010"  -or $_ -eq "SharePointServer2010"} {$sutShortVersion = "14.0"; break}
     {$_ -eq "SharePointFoundation2013" -or $_ -eq "SharePointServer2013"} {$sutShortVersion = "15.0"; break}   
    }
  
    $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
    $credential = new-object Management.Automation.PSCredential($userName,$securePassword)

    $isStandaloneInstallation = invoke-command -computer $computerName -Credential $credential -ErrorAction SilentlyContinue -scriptblock{
 param(
    [string]$sutShortVersion
    )
  
     $ServerModeChildItem = get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\$sutShortVersion\WSS"
        $isStandaloneInstallation = "false"
        if($ServerModeChildItem.ServerRole -ieq "SINGLESERVER")
        {
            $isStandaloneInstallation = "true"
        }
        return $isStandaloneInstallation
  
    }-ArgumentList $sutShortVersion
 
    if($isStandaloneInstallation -eq $null -or $isStandaloneInstallation -eq "")
    {
  Output "Select the SUT server installation mode: " "Cyan"
        Output "1: Standalone mode" "Cyan"
        Output "2: Farm mode" "Cyan"

        $isStandaloneInstallation = @('1','2')
        While(1)
        {
            [String]$readLine = Read-Host
            if($isStandaloneInstallation -contains $readLine)
            {
                break
            }
            else
            {
                Output """$readLine"" is not a correct input, retry with a correct number from the values listed." "Yellow"
            }
        }

        if ($readLine -eq "1")
        {
            $isStandaloneInstallation = "true"
   Output "Your input SUT server installation mode is StandAlone" "Yellow"
        }
        else
        {
            $isStandaloneInstallation = "false"
   Output "Your input SUT server installation mode is Farm" "Yellow"
        }
       
    }     
 
    return $isStandaloneInstallation 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值