Powershell Microsoft.win32.registrykey Openremotebasekey Credentials



The nice thing about this command is you can also specify alternate credentials. However, it does require that WsMan is correctly configured for powershell remoting to work. Which, 9 times out of 10 in most environments it is not. Option 2 – The Microsoft.Win32.RegistryKey Class. The nice thing about this command is you can also specify alternate credentials. However, it does require that WsMan is correctly configured for powershell remoting to work. Which, 9 times out of 10 in most environments it is not. Option 2 – The Microsoft.Win32.RegistryKey Class.

This is one of those posts so I never have to google this again (one hopes). Here is the PS code to pull back a set of details about every SSRS instance installed on a server including the SSRS instance name, & the first URL port it is running on, the service name and the name of the report server database etc.

$servername='myserver'
$key='SoftwareMicrosoftMicrosoft SQL Server'
$reg= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$server)
$regKey=$reg.OpenSubKey($key)
$keys=$regKey.GetSubKeyNames()
$v=0
foreach($kin$keys)
{
if(( $k-match'MSRS[dd].') -and ($k-notcontains'@'))
{
$pv=$k.Substring(4,2)
if ($v-le$pv)
{
$v=$pv
$rs='RS_'+$k.Substring($k.IndexOf('.') +1)
}
}
}
$nspace='rootMicrosoftSQLServerReportServer$rsv$vAdmin'
$RSServers=Get-WmiObject-Namespace $nspace-class MSReportServer_ConfigurationSetting -ComputerName $servername-ErrorVariable perror -ErrorAction SilentlyContinue
foreach ($rin$RSServers)
{
#https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/msreportserver-configurationsetting-members?view=sql-server-2017
$ssrsHost=$r.InstanceName
$ssrsVers=$r.version
$ssrsDB=$r.DatabaseName
$ssrsShare=$r.IsSharePointIntegrated
$ssrsService=$r.ServiceName
$vPath=$r.VirtualDirectoryReportServer
$urls=$r.ListReservedUrls()
$urls=$urls.UrlString[0]
$urls=$urls.Replace('+',$servername) +'/$vPath'
# do a thing with this specific SSRS instance details
$ssrsHost
$ssrsVers
$ssrsDB
$ssrsShare
$ssrsService
$vPath
$urls
}

Discussion

Although PowerShell does not directly let you access and manipulate the registry of a remote computer, it still supports this by working with the .NET Framework. The functionality exposed by the .NET Framework is a bit more developeroriented than we want, so we can instead use a script to make it easier to work with.

Example 188 lets you set the value of a property on a given remote registry key. In order for this script to succeed, the target computer must have the remote registry service enabled and running.

Example 188. SetRemoteRegistryKeyProperty.ps1

############################################################################## ## ## SetRemoteRegistryKeyProperty.ps1 ## ## Set the value of a remote registry key property ## ## ie: ## ## PS >$registryPath = ## 'HKLM:softwareMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell' ## PS >SetRemoteRegistryKeyProperty LEEDESK $registryPath ` ## 'ExecutionPolicy' 'RemoteSigned' ## ##############################################################################

param( $computer = $(throw 'Please specify a computer name.'), $path = $(throw 'Please specify a registry path'), $property = $(throw 'Please specify a property name'), $propertyValue = $(throw 'Please specify a property value') )

## Validate and extract out the registry key if($path match '^HKLM:(.*)') {

Credentials

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey Reader rabbit mac download.

('LocalMachine', $computer) } elseif($path match '^HKCU:(.*)') {

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey ('CurrentUser', $computer) }

Example 188. SetRemoteRegistryKeyProperty.ps1 (continued)

Registrykey

else { WriteError ('Please specify a fullyqualified registry path ' + '(i.e.: HKLM:Software) of the registry key to open.') return }

C# Registrykey

## Open the key and set its value $key = $baseKey.OpenSubKey($matches[1], $true) $key.SetValue($property, $propertyValue)

Powershell Openbasekey

## Close the key and base keys $key.Close() $baseKey.Close()