我如何在AD中添加或者添加描述我想离开当前的描述并且在它的前面添加一些文本
例如一台电脑的描述为“会计部”(不含引号)
我试过这个:
set-QADComputer -Identity computername -Description {Disabled 8/17/2012, Termrpt "$($_.description)"}
我得到这个描述
已禁用2012/8/17,“$($ _。description)”
但是我想要像下面这样的文本前面的原始描述
残疾2012年8月17日,会计部
有任何想法吗?
我尝试了括号,但是它只是把前置文本和原始文件抹掉。
我不使用QWEST AD cmdlet,因此我不知道确切的语法,但通常最好的方法是检索当前的描述,将其保存到一个variables,然后将$ Current_Desc + $ addendum写回到目的。
我不使用Qwest模块。 如果您愿意使用RSAT附带的Microsoft AD模块,则以下内容非常简单。
Import-Module ActiveDirectory # Let's check the Description Get-ADUser jscott -Properties Description | Select-Object -Property Description Description ----------- Junior Keyboard MRO Tech # Cool, set it the new value Get-ADUser jscott -Properties Description | ForEach-Object { Set-ADUser $_ -Description "Disabled 8/17/2012, Termrpt $($_.Description)" } # Let's check the new Description Get-ADUser jscott -Properties Description | Select-Object -Property Description Description ----------- Disabled 8/17/2012, Termrpt Disabled Junior Keyboard MRO Tech
我觉得让你恼火的是使用$_作为cmdlet的参数,而不是在脚本块中。 我在ForEach_Object封装了Set-ADUser ,确保$_是pipe道中的对象。 在脚本块之外,使用$_作为参数将返回$null 。
除了MDMarra的回答(打败我),你也可以设置一个stringvariables等于一个附加值+= ,所以类似$Description += "blah"将追加“等等”到你的variables值。
( $Description += "blah"是简短的$Description = $Description + "blah" )