Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Creating a registry key on a remote machine

$
0
0

When using the follwoing to create a key, the result is not as expected. what is wrong? Thanks

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $ip)
$key = $baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\",$true)
$key.CreateSubKey('mapdrives')
$key.SetValue('mapdrives', 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File "C:\mapdrives.ps1"')

the expected result:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
"mapdrives"="C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Unrestricted -File \"C:\\mapdrives.ps1\""


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>