Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Registry Keys on multiple SQL instances

$
0
0
Hello,I can't figure this out.... I'm on PowerShell version 2, and version 4, and just starting to learn PS.This is a very basic code to find the location of the errorlog on the registry.I know we can do that by connecting to SQL, but this is intended to our SysAdmin friends that don't have access to SQL (non-DBAs), and for machines that I don't support and I cant get to it, but still want to helpI want to be able to tell them "run this powershell" and send the the file!I have the following script:[code="vb"] # Searches for SQL server installed on machine $RegKey = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL??*\MSSQLServer\parameters" # Filter -e for errorlog. -d for master file $Filter = "-e" # Stores a list of the SQLArg Registry Keys $Param1 = Get-Item $RegKey | Select-Object -ExpandProperty property # Creates an Object, and filters those starting with the filter $Param2 = $Param1 | ForEach-Object { New-Object psobject -Property @{"property"=$_; "Value" = (Get-ItemProperty -Path $RegKey -Name $_).$_}} # Finally, removes -e from the string $Param3 = (($Param2 | Where-Object {$_.Value -like ($Filter+"*") }).Value).Replace($Filter,"") New-Object psobject -Property @{"Path"=$Param3 ; "ServerName" = $env:COMPUTERNAME}[/code]However, the code does not work when we have more than one instance installed.The reason is that $Param1 returns an array ( SQLArg0, SQLArg1, SQLArg2, SQLArg0, SQLArg1, SQLArg2) and then when I run this part of code...:Get-ItemProprty -Path $Regkey -Name $Param1I get the error[code="other"]Get-ItemProperty : The member "SQLArg0" is already present.At line:1 char:17+ Get-ItemProperty <<<< -Path $RegKey -Name $Param1 + CategoryInfo : NotSpecified: (:) [Get-ItemProperty], ExtendedTypeSystemException + FullyQualifiedErrorId : AlreadyPresentPSMemberInfoInternalCollectionAdd,Microsoft.PowerShell.Commands.GetItemPro pertyCommand[/code]So I need to somehow loop, but I can't figure out how to loop here...Suggestions? Resources?ThanksMiguelwww.cookingsql.com

Viewing all articles
Browse latest Browse all 467

Trending Articles