Home > Net >  Powershell Select and Use Specific Value
Powershell Select and Use Specific Value

Time:09-02

I am preparing a script. What I want to do is to get the user SID from Active Directory and use it in another command.

I tried to do this command but couldn't run it

$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"

Thanks.

CodePudding user response:

simply do this:

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

CodePudding user response:

It worked like this. :)

$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"

Thanks everyone.

  • Related