删除CN中的空格 [英] Remove spaces in CN
问题描述
非常感谢提前!
我需要从CN中删除各种域用户对象的所有空格,这些空间通常在它们的名字和姓氏之间。  我试图构建一些基本上从CN移除所有空格的东西,无论位置如何......前导,中间,
尾随...只是将非空格字符粉碎在一起。
<我真的很陌生,我剽窃弗兰肯斯坦就是我在很多线上看过的东西,试图自学并弄清楚结构,所以我可能会偏离基础。
<到目前为止我已经做到了这当然不起作用:
clear
Import-Module ActiveDirectory
$ ou =" DC = domain,DC = com"
$ server =" server1.domain.com"
Get-ADUser -server $ server -SearchBase $ ou - 过滤器{CN-like" * *"} | ForEach-Object {
$
$ newCN = $ _。CN -replace'/ s'''| Set-ADUser -server $ server -CN $ newCN -Verbose -Whatif
}
我在下注有一种更简单的方法,但试图保持半简单,让我调整各种域的东西,并清除CN中的空格。
任何帮助将不胜感激,以及任何解释或说明为什么这个或那个!
'john Jeffery jones II Jr.'-replace'',''
Get-ADUser -server
server -SearchBase
ou -filter'CN -like " * *"'|
ForEach-Object {
Hi and many thanks in advance!
I need to remove all spaces from the CN of various domain user objects, which are generally in between their first and last name. I am trying to compose something that basically removes all spaces from the CN regardless of location...leading, middle, trailing...just smash the non-space characters together.
I am really new to PS and am plagiaristically Frankenstein'ing what I've seen on numerous threads, trying to teach myself and figure out the structure, so I might be WAY off base.
I have made this so far which of course isn't working:
clear
Import-Module ActiveDirectory
$ou = "DC=domain,DC=com"
$server = "server1.domain.com"
Get-ADUser -server $server -SearchBase $ou -filter {CN -like "* *"} | ForEach-Object {
$newCN = $_.CN -replace '/s''' | Set-ADUser -server $server -CN $newCN -Verbose -Whatif
}
I'm betting there is an easier way but trying to keep it semi-simple, let me adjust things for various domains and purge spaces in the CN.
Any help would be greatly appreciated, along with any explanations or instruction as to why this or that!
'john Jeffery jones II Jr.' -replace ' ',''
Get-ADUser -server
server -SearchBase
ou -filter 'CN -like "* *"' |
ForEach-Object {
这篇关于删除CN中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!