小编Joc*_*Sch的帖子

Powershell:如果字符串以

有没有办法检查,如果一个字符串以字符串开头?

我们正在检查AD用户的组成员身份.我们的广告组看起来像这样:S_G_share1_W

用于连接网络共享的脚本只应在组名开头时运行"S_G_",因为我们也有其他组.

$GroupArray = Get-ADPrincipalGroupMembership $env:USERNAME | select samaccountname

foreach ($Group in $GroupArray) {

    if ($Group.StartsWith("S_G_")) {

        $Group = $Group -replace "S_G_", $FileServerRV
        Write-Host $Group

        $Group = $Group.Substring(0, $Group.Length-2)
        Write-Host $Group

        #erstellen des Anzeigennames
        $Groupname = $Group.Replace($FileServerRV, "")
        Write-Host "Call Function with parameter "$Group $Groupname
    }
}
Run Code Online (Sandbox Code Playgroud)

powershell if-statement startswith

27
推荐指数
1
解决办法
8万
查看次数

标签 统计

if-statement ×1

powershell ×1

startswith ×1