Powershell - AD 对象的“注释”字段中的换行符

问题描述 投票:0回答:2

我已经在 AD 中设置了自动创建用户的脚本。 除了一件事之外,一切都运转良好。 AD 对象的索引选项卡 Telephones 中的 Notes 字段似乎忽略了 Powershell 中添加的任何换行符。

$notes = "E-Mail: $mail`nPhone: $phone`nInternal Contact:$contact"

#random irrelevant code in between

OtherAttributes   = @{
        'info' = $notes
}

OtherAttributes 也是包含其他 AD 用户参数的哈希表的一部分。

1) 现状和 2) 应该如何的屏幕截图。

这可能吗?

手动执行时没有任何问题,所以我假设必须有一种方法让它通过脚本工作。

powershell active-directory line-breaks
2个回答
0
投票

如果您想在单双引号行中创建注释,请使用 Windows 换行符 (CRLF),如 Mathias 已评论:

$notes = "E-Mail: $mail`r`nPhone: $phone`r`nInternal Contact: $contact"

或使用 -f 格式运算符:

填写这些内容
$notes = "E-Mail: $mail{0}Phone: $phone{0}Internal Contact: $contact" -f [Environment]::NewLine

也许更好的方法是使用 Here-String:

$notes = @"
E-Mail: $mail
Phone: $phone
Internal Contact: $contact
"@

0
投票

这可能不是最好的解决方案,但它是我使用的。

我创建了一个名为 $nls 的变量,并在其中放置了一个返回值以在我的连接字符串中使用。它使内容更容易阅读。

$nls =“

© www.soinside.com 2019 - 2024. All rights reserved.