SQL root directory and PowerShell

SQLDBA2109 6 Reputation points

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,166 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Limitless Technology 38,756 Reputation points

    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.




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

  2. Rich Matheisen 42,826 Reputation points

    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 42,826 Reputation points

    How about this?