我是PowerShell的新手,需要搜索开发人员(dev-)或admin(ad-)等特殊帐户,关闭前缀并查看该用户是否拥有帐户(sAMAccountName)
下面,我可以从我的域中搜索并获取所有特殊帐户,但我需要编写整个过程的脚本,因此我只返回没有常规用户帐户的特殊帐户。
ForEach ($acct in "Dev-*","dev-*","rl-*","cafe-*","dev-dev-*","ad-*", `
"sa-*","AD-*","ir-*","tst-*","o365-*","te-*","la-*","vmtest-*", `
"mtep-*","EIM-*","GRT*","cbl-","DS-*","fim-*") {
Get-ADUser -Filter {sAMAccountName -like $acct} -SearchBase "DC=xxx,DC=xxx,DC=com" `
-Properties sAMAccountName | Select sAMAccountName
}
答案 0 :(得分:0)
它并不漂亮,但您可以删除找到的用户名的前缀并搜索该用户。如果没有返回(不匹配),请继续使用开发帐户,否则将其删除。例如:
static void updateConfigurationWith(Properties propertyFile, boolean append) {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
propertyFile.store(bytes, propertyFile.getProperty("test.name"));
ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
Function<String, BiFunction<String,String,String>> remapper =
append ? (x) -> ((o, n) -> n == null ? o : n)
: (x) -> ((o, n) -> n);
LogManager.getLogManager().updateConfiguration(bais, remapper);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}