vendredi 26 février 2016

How to check if strings starts with

Is there any way to check, if a string starts with a string?

We are checking the group membership from the AD user. Our AD groups look like this: S_G_share1_W The script for connecting the network shares should only run, if the groupname starts with "S_G_", because we have some other groups too.

$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

    }
}

Aucun commentaire:

Enregistrer un commentaire