我有一个脚本,可以将一些 AD 属性导出到 csv 我想在 PsObject 中包含“首字母”属性的最后 3 个字符,但我有一个错误,我花了几个小时在这上面……你能帮帮我吗?
错误:
*Method invocation failed because [Microsoft.ActiveDirectory.Management.ADUser] doesn't contain a method named 'substring'.
At C:\scripts\ExtractDWH\Untitled2.ps1:15 char:26
+ "Test" = $_.substring <<<< ($_.initials.length - 3, 3)
+ CategoryInfo : InvalidOperation: (substring:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound*
编码 :
$output = 'c:\scripts\ExtractDWH\consultants_test.csv'
$users = Get-ADUser -Filter * -SearchBase "ou=Rennes,ou=Consultants,ou=Utilisateurs,ou=FedFinance,dc=dfedinterim,dc=fr" - Properties * | ? { ($_.initials -notlike 'IC*') -and ($_.initials -notlike 'IM*') -and ($_.initials -ne $null) }
fileIn | % {
$users | % {
New-Object psobject -Property @{
"ID" = $_.initials
"Last 3 strings ID" = $_.substring($_.initials.length - 3, 3)
"Centre Imputation" = $_.extensionAttribute10
"Date Entrée" = $_.extensionAttribute9
# The line below does not work
"Test" = $_.substring($_.initials.length - 3, 3)
}
}
} | Select-Object ID, 'Centre Imputation', 'Date Entrée', 'Test'
| Export-CSV $output -Delimiter ';' -Encoding "UTF8" -NoTypeInformation `
谢谢 !