Asked by:
Store registry value output in a variable

Question
-
Hello! i have been working on script to get the value of a remote registry key. I have tried alot of different versions from technet and stuff i googled and found a version that works for me:
$key = 'Software\MyCompany\OurSoftware' $valuename = 'Computer Type' $computers = Get-Content C:\dev\Data\Computers.csv $serviceRunning = [System.ServiceProcess.ServiceControllerStatus]::Running $serviceDisabled = [System.ServiceProcess.ServiceStartMode]::Disabled foreach ($computer in $computers) { $svc = Get-Service -Name RemoteRegistry -ComputerName $computer if ( $svc.StartType -eq $serviceDisabled ) { $svc | Set-Service -StartupType Manual } if ( $svc.Status -ne $serviceRunning ) { $svc| Start-Service } $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer) $regkey = $reg.opensubkey($key) $regkey.getvalue($valuename) $svc | Stop-Service $svc | Set-Service -StartupType Disabled }
Is there a way to store the value output into a variable?
Is there a way for me to store the value output in a variable?
Is there a way for me to store the value output in a variable?
- Edited by P0ntus Andreasson Tuesday, March 17, 2020 8:47 AM
Tuesday, March 17, 2020 8:10 AM
All replies
-
Start by editing and fixing your post. Please read the following for instructions:
\_(ツ)_/
Tuesday, March 17, 2020 8:14 AM -
Thank you.
First remove the following:
$ErrorActionPreference = "SilentlyContinue"
\_(ツ)_/
Tuesday, March 17, 2020 8:29 AM -
To store output in a variable when in a loop you will need to completely restructure your code to work correctly.]
\_(ツ)_/
- Edited by jrv Tuesday, March 17, 2020 8:49 AM
Tuesday, March 17, 2020 8:39 AM -
The best place to start to learn what a variable is and how to use it is by reading the help
help about_Variables
\_(ツ)_/
Tuesday, March 17, 2020 9:04 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Yang YangTuesday, March 24, 2020 1:53 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Yang YangThursday, April 2, 2020 5:47 AM