2017-03-23 16 views
1

動作しない、私はそれ以外の場合は、それを検索することはできません、検索およびグループのために文字列の一部を削除したいのですが、Replace()/Remove()が動作していません。文字列に置き換え()/(削除)

$RootPath = $Selection 
    $Folders = dir $RootPath | where {$_.PSIsContainer -eq $true} 
    try { 
     foreach ($Folder in $Folders) { 
      $ACLs = Get-Acl $Folder.FullName | ForEach-Object { 
       $_.Access 
      } 
      foreach ($ACL in $ACLs) { 
       if ($ACL.IdentityReference -notlike "Administrators" -and $ACL.IdentityReference - notlike "Creator Owner" - and $ACL.IdentityReference -notlike "BUILTIN\Administrators" -and $ACL.IdentityReference -notlike "NT AUTHORITY\SYSTEM" -and $ACL.IdentityReference -notlike "System") { 
        $strAcl = $ACL.IdentityReference 
        # value is for instance GESCOEUROPE\GR_G-FCASB-INT-ALL 
       } 
      } 
     } 

     $strNames = $strAcl.Replace("GESCOEUROPE\", "") 
     # or: 
     #$strNames = $strAcl.Remove(0, 12) 

     $strUsers = Get-ADGroupMember -Identity $strNames -Recursive | 
        Get-ADUser -Property DisplayName | 
        Select Name | 
        Sort-Object Name 
     $OutInfo = $Folder.FullName + "," + $trAcl + $strUsers 
     $OutInfo | Select-Object -Unique 
     Add-Content -Value $OutInfo -Path $OutFile | Sort-Object -Unique 
    } catch [System.IO.IOException] { 
    } 
} 
+0

を試してみてください:あなたのコードは、複数のフォルダを超えると、そのACLをそれぞれをループが、唯一のこれまで '$ strAcl'で_single_値を保存します。 – mklement0

答えて

4

[System.Security.Principal.NTAccount]Get-Memberで確認)の$strAcl$ACL.IdentityReferenceを設定します。 ではない文字列ですので、.Replace()に電話することはできません。あなたが$ACL.IdentityReferenceを文字列化する場合

、それに.ToString()を呼び出す、または[string]にキャスト、または二重引用符で囲まれた文字列内の式で囲む:

# Call .ToString() 
$strAcl = $ACL.IdentityReference.ToString() 

# Cast to [string] 
$strAcl = [string] $ACL.IdentityReference 

# Use string interpolation: 
$strAcl = "$($ACL.IdentityReference)" 

注:でこの場合、他の2つの方法は、敏感を常に本培養であるのに対し、すべての3つの方法が同等であるが、.ToString()[1] 培養に敏感である場合があります。


[1]余談として[cultureinfo]::CurrentCulture = 'de-DE'; (0.5).ToString(); [string] 0.5; "$(0.5)"

関連する問題