将 ScriptPath 从一个用户复制到另一个用户
Issue copying ScriptPath from one user to another
您好,我在 PowerShell 中将 ScriptPath 从一个用户复制到另一个用户时遇到问题。
$currentUserScriptPath = Get-ADUser -Identity currentuser -Properties ScriptPath | Select ScriptPath
Set-ADUser -Identity newuser -ScriptPath $currentUserScriptPath
UserProperties
这就是我得到的登录脚本。我想要的只是 .bat 脚本。我确定这是我想念的愚蠢的东西。任何帮助将不胜感激。
要仅从变量中获取值,您可以将 $currentUserScriptPath
更改为:
$currentUserScriptPath = (Get-ADUser -Identity currentuser -Properties ScriptPath).scriptpath
或
$currentUserScriptPath = Get-ADUser -Identity currentuser -Properties ScriptPath | Select ScriptPath -expandproperty scriptpath
您应该添加一个测试以查看用户 currentuser
的 ScriptPath 属性 是否为空,并且仅在用户 newuser
是否为空时设置。
$currentUserScriptPath = (Get-ADUser -Identity currentuser -Properties ScriptPath).ScriptPath
if ([string]::IsNullOrWhiteSpace($currentUserScriptPath)) {
# the currentuser has an empty ScriptPath property.
# if you want the newuser to also have its scriptPath removed, uncomment the next line
# Set-ADuser -Identity newuser -Clear scriptPath
}
else {
Set-ADUser -Identity newuser -ScriptPath $currentUserScriptPath
}
您好,我在 PowerShell 中将 ScriptPath 从一个用户复制到另一个用户时遇到问题。
$currentUserScriptPath = Get-ADUser -Identity currentuser -Properties ScriptPath | Select ScriptPath
Set-ADUser -Identity newuser -ScriptPath $currentUserScriptPath
UserProperties 这就是我得到的登录脚本。我想要的只是 .bat 脚本。我确定这是我想念的愚蠢的东西。任何帮助将不胜感激。
要仅从变量中获取值,您可以将 $currentUserScriptPath
更改为:
$currentUserScriptPath = (Get-ADUser -Identity currentuser -Properties ScriptPath).scriptpath
或
$currentUserScriptPath = Get-ADUser -Identity currentuser -Properties ScriptPath | Select ScriptPath -expandproperty scriptpath
您应该添加一个测试以查看用户 currentuser
的 ScriptPath 属性 是否为空,并且仅在用户 newuser
是否为空时设置。
$currentUserScriptPath = (Get-ADUser -Identity currentuser -Properties ScriptPath).ScriptPath
if ([string]::IsNullOrWhiteSpace($currentUserScriptPath)) {
# the currentuser has an empty ScriptPath property.
# if you want the newuser to also have its scriptPath removed, uncomment the next line
# Set-ADuser -Identity newuser -Clear scriptPath
}
else {
Set-ADUser -Identity newuser -ScriptPath $currentUserScriptPath
}