繁体   English   中英

Powershell Select 和使用具体值

[英]Powershell Select and Use Specific Value

我正在准备一个脚本。 我想要做的是从 Active Directory 获取用户 SID 并在另一个命令中使用它。

我尝试执行此命令但无法运行它

$username = Read-Host -Prompt 'Erdem.OV'
$SID = Get-ADUser -Identity $username | select-object SID
$PSExec = "C:\Windows\System32\PsExec.exe"
$hostname = Read-Host -Prompt 'hostname'

$command = 'cmd /c "reg add "HKEY_USERS\"$SID"\SOFTWARE\Policies\Microsoft\Internet Explorer\Control Panel" /v ConnectionsTab /t REG_DWORD /d 0"'

Start-Process -Filepath "$PsExec" -ArgumentList "\\$hostname $command"

谢谢。

只需这样做:

(Get-ADUser -Identity $username).sid.value

它是这样工作的。 :)

$username = Read-Host -Prompt 'Username'
$SID = (Get-ADUser -Identity $username).sid.value
$PSExec = "C:\Windows\System32\PsExec.exe"
$hostname = Read-Host -Prompt 'hostname'

$command = 'cmd /c'
$command2 = '"reg add "HKEY_USERS\'
$command3 = '\SOFTWARE\Policies\Microsoft\Internet Explorer\Control Panel" /v ConnectionsTab /t REG_DWORD /d 0"'

Start-Process -Filepath "$PsExec" -ArgumentList "\\$hostname $command $command2$SID$command3"

感谢大家。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM