Powershell 字符串替换()/Remove()不';行不通

Powershell 字符串替换()/Remove()不';行不通,powershell,Powershell,我想删除搜索和分组字符串的一部分,否则它无法搜索,但Replace()/remove()不起作用: $RootPath=$Selection $Folders=dir$RootPath |其中{$\ PSIsContainer-eq$true} 试一试{ foreach($文件夹中的文件夹){ $ACLs=获取Acl$Folder.FullName | ForEach对象{ $\访问 } foreach($ACL中的ACL){ if($ACL.IdentityReference-不象“Admin

我想删除搜索和分组字符串的一部分,否则它无法搜索,但
Replace()
/
remove()
不起作用:

$RootPath=$Selection
$Folders=dir$RootPath |其中{$\ PSIsContainer-eq$true}
试一试{
foreach($文件夹中的文件夹){
$ACLs=获取Acl$Folder.FullName | ForEach对象{
$\访问
}
foreach($ACL中的ACL){
if($ACL.IdentityReference-不象“Administrators”-和$ACL.IdentityReference-不象“Creator Owner”-和$ACL.IdentityReference-不象“BUILTIN\Administrators”-和$ACL.IdentityReference-不象“NT AUTHORITY\SYSTEM”-和$ACL.IdentityReference-不象“SYSTEM”){
$strAcl=$ACL.IdentityReference
#例如,值为GESCOEUROPE\GR_G-FCASB-INT-ALL
}
}
}
$strNames=$strAcl.Replace(“GESCOEUROPE\”,“”)
#或:
#$strNames=$strAcl.Remove(0,12)
$strUsers=Get-ADGroupMember-Identity$strNames-Recursive|
获取ADUser-属性DisplayName|
选择名称|
排序对象名
$OutInfo=$Folder.FullName+“,”+$trAcl+$strUsers
$OutInfo |选择对象-唯一
添加内容-值$OutInfo-路径$OutFile |排序对象-唯一
}catch[System.IO.IOException]{
}
}

您将
$strAcl
设置为
$ACL.IdentityReference
,类型为
[System.Security.Principal.NTAccount]
(使用验证);它不是字符串,因此不能对其调用
.Replace()

如果要字符串化
$ACL.IdentityReference
,请对其调用
.ToString()
,或将其强制转换为
[string]
,或将其包含在双引号字符串中的表达式中:

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

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

# Use string interpolation:
$strAcl = "$($ACL.IdentityReference)"
注意:在这种情况下,所有3种方法都是等效的,但在某些情况下,
.ToString()
是区域性敏感的[1] ,而其他两种方法始终不区分区域性



[1] 尝试
[cultureinfo]::CurrentCulture='de';(0.5)ToString();[字符串]0.5;“$(0.5)”

您将
$strAcl
设置为
$ACL.IdentityReference
,类型为
[System.Security.Principal.NTAccount]
(使用验证);它不是字符串,因此不能对其调用
.Replace()

如果要字符串化
$ACL.IdentityReference
,请对其调用
.ToString()
,或将其强制转换为
[string]
,或将其包含在双引号字符串中的表达式中:

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

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

# Use string interpolation:
$strAcl = "$($ACL.IdentityReference)"
注意:在这种情况下,所有3种方法都是等效的,但在某些情况下,
.ToString()
是区域性敏感的[1] ,而其他两种方法始终不区分区域性



[1] 尝试
[cultureinfo]::CurrentCulture='de';(0.5)ToString();[字符串]0.5;“$(0.5)”

作为旁白:代码在多个文件夹及其每个ACL上循环,但仅在
$strAcl
中保存一个值。作为旁白:代码在多个文件夹及其每个ACL上循环,但仅在
$strAcl
中保存一个值。