SQL root directory and PowerShell

SQLDBA2109 6 Reputation points
2022-08-24T04:16:32.99+00:00

How can I get PowerShell scripting to get information About SQL root directory?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Limitless Technology 39,351 Reputation points
    2022-08-24T13:42:09.32+00:00

    Hello there,

    There are two SQL Server PowerShell modules; SqlServer and SQLPS.
    The SqlServer module is the current PowerShell module to use.

    The Get-SqlInstance cmdlet gets a SQL Instance object for each instance of SQL Server that is present on the target computer. If the name of the instance of SQL Server is provided, the cmdlet will only get this specific instance of SQL Server.

    https://learn.microsoft.com/en-us/powershell/module/sqlserver/get-sqlinstance?view=sqlserver-ps

    https://learn.microsoft.com/en-us/sql/powershell/navigate-sql-server-powershell-paths?view=sql-server-ver16

    ------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--


  2. Rich Matheisen 44,776 Reputation points
    2022-08-24T18:41:00.41+00:00

    You can try either (or both) of these bits of code:

    Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |   
        ForEach-Object {  
            Get-ItemProperty $_.PsPath } |   
                Select-Object DisplayName,InstallLocation  
      
    Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |   
        ForEach-Object {   
            Get-ItemProperty $_.PsPath } |   
                Select-Object DisplayName,InstallLocation  
    

    Not everything in these registry keys has an InstallationLocation directory.

    If you're doing this on remote machines, you might find this an easier way to get the information. However, wrapping the other code in a script block and using Invoke-Command would run a lot faster:

    Get-WmiObject -Computer RemoteComputer -Class Win32_Product |   
        Select-Object Caption,InstallLocation  
    

    If you know at least part of the product name you can add something like this to the Get-WmiObject -Filter 'Name like "%Microsoft. You can also add a Where-Object to the other code to return less information.


  3. Rich Matheisen 44,776 Reputation points
    2022-10-07T15:10:07.747+00:00

    How about this?

    sql-server-root-directory