Cant work out why this bit of PS isnt working

  • hello,

    I am following an online tutorial to help me learn powershell. It's pretty good but I have a piece of code from it, and although typed exactly correct, is not working and I cant figure out why, would love to know...

    $instance = $args[0]

    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null

    $ServerInstance = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $instance

    Write-Host "Name: " $ServerInstance.Name

    Write-Host "Edition: " $ServerInstance.Edition

    Write-Host "Version: " $ServerInstance.Version

    Write-Host "ProductLevel: " $ServerInstance.ProductLevel

    ...It returns the name, but nothing else.

    Thank you.

    Regards,

    D.

    PS: Does anybody know of a good resource that will teach me to create SQL connection strings to SQL from a powershell console that can be used in a script, please? Thank you.

  • NOTE: If you could provide the actual output that would help.

    Possible security permissions?

    I always go to ConnectionStrings.com as a starter when I cannot remember off the top of my head for simple connection related examples.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Hi Gary, thank you for responding.

    Yes, the result would be handy! Sorry!

    GAC Version Location

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

    True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll

    True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.SmoExtended\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SmoExtended.dll

    PS C:\WINDOWS\system32> H:\Documents\Tutorial.ps1

    Name: AU20A9LP9013

    Edition:

    Version:

    ProductLevel:

    PS SQLSERVER:\>

    ...thanks for the connection string pointer, I'll check it out. It wont be permissions, as I have SA on the instance.

    Thank you.

    Regards,

    D.

  • The problem you have with that script is in the way you are calling it.

    Your script contains the line $instance = $args[0]. This line is is grabbing the value being passed into the script. So the correct way to call this script is going to be:

    .\Test.ps1 'MANATARMS\SQL12'

    In this I am passing in my instance that runs on my local machine. If you don't pass any argument you are getting back the hostname of the computer you run it on, which would be the default. I do not have a default instance, which this is some what of the issue you have with SMO. If you don't connect to the SQL Server instance it will not necessarily give you any error, the values will just be empty (or null).

    An example run of this script:

    Now, to make a few points on the way this script is written that will more follow the way you should write a PowerShell script:

    - Use of "$args" is something that works, but does not allow for an easily read script.

    - Just so you are aware using "[System.Reflection.Assembly]" is something used from PowerShell version 1.0. It is a method that as of .NET 2.0 has been marked "obsolete".

    - In PowerShell scripts Write-Host is something that is common use for some folks, but to just give you a good start there is a better way. When you are outputting data from a script you should always strive to make it output as an object. Using "Write-Host" it just becomes a string, making it an object allows you to more easily come back around and expand on this script; or if you have a second process that needs that output it will be easier to accept as input.

    I am not sure what tutorial you are using but I can suggest the Stairway Series on PowerShell[/url] is a good start. I also did a series on PowerShell, more like a jump start geared toward DBAs[/url].

    The way I would write this script:

    [cmdletbinding()]

    param (

    [string]$instance

    )

    Add-Type -AssemblyName "Microsoft.SqlServer.Smo,Version=11.0.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91"

    $ServerInstance = New-Object Microsoft.SqlServer.Management.Smo.Server $instance

    $ServerInstance | Select Name, Edition, Version, ProductLevel

    Example Output:

    If you wanted to create a custom object so you could "change" the property name, and then also pass this object as output:

    [cmdletbinding()]

    param (

    [string]$instance

    )

    Add-Type -AssemblyName "Microsoft.SqlServer.Smo,Version=11.0.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91"

    $ServerInstance = New-Object Microsoft.SqlServer.Management.Smo.Server $instance

    $props = @{InstanceName="";Edition="";BuildNumber="";ServicePackLevel=""}

    $results = New-Object -TypeName psobject -Property $props

    $results.InstanceName = $ServerInstance.Name

    $results.Edition = $ServerInstance.Edition

    $results.BuildNumber = $ServerInstance.Version

    $results.ServicePackLevel = $ServerInstance.ProductLevel

    $results

    Example output:

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Shawn,

    Thank you so much for your detailed answer, I shall have to read through it a few time to digest it all! In regards to the "[System.Reflection.Assembly]", when I first started out I was indeed using the Add Type way, then as I was looking for more examples to follow and learn I came across that, I didn't realise that it was an out-dated way of doing that, so thank you for pointing that out, I am just starting the Stairway series, I'll also check out the other link as well.

    Again, thank you very much.

    Regards,

    D.

  • Hello,

    I'm now trying to get a list of SQL services from a remote machine, and I feel like I am almost there, but there are one or two things I just don't understand. The first bit of PS above the dashed line, gets me what I want but only on the local host, if I put in a FQDN of the remote computer, including the port number, it still only gives me the local host. I don't get that.

    The piece of code I have after the line, I'm trying to get it to put all the output into an excel document, the excel document opens up and all the headers appear, but I cant work out what I am doing wrong, or what is missing, that is preventing the output from filling in the cells with the required info, I do not think the .TXT file is getting read either, I cant see what's missing to prevent that, the file is in place.

    I've learnt quite a bit over the last two weeks, but I am struggling with this latest hurdle. Any help is greatly appreciated.

    Also I keep reading that it is not a good idea to use SQLPS, as there is no more dev time being spent on it, and I should 'Add-Type' instead, is this correct and if so, should I avoid getting the assembles from the GAC?

    Import-Module SQLPS -DisableNameChecking

    $InstanceName = "NAME OF REMOTE INSTANCE OF SQL SERVER"

    $folder = "H:\temp1"

    $currdate = Get-Date -Format "yyyy-MM-dd"

    $filename = "$($InstanceName)_ListServices_$($currdate).csv"

    $fullpath = Join-Path $folder $filename

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    #List Services

    $managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState |

    Export-Csv -Path $fullpath -NoTypeInformation

    #export result to csv

    explorer $folder

    #-----------------------------------------------------------------------------------------------------------------------

    Import-Module SQLPS -DisableNameChecking

    #Create a new Excel object using COM

    $Excel = New-Object -ComObject Excel.Application

    $Excel.visible = $True

    $Excel = $Excel.Workbooks.Add()

    $Sheet = $Excel.Worksheets.Item(1)

    $intRow = 1

    ForEach ($Instancename in Get-Content "H:\Documents\DevServers.txt")

    {

    #$managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    $intRow++

    #Create column headers

    $Sheet.Cells.Item($intRow,1) = "Name:" #$managedcomputer.Services

    $Sheet.Cells.Item($intRow,1).Font.Size = 12

    $Sheet.Cells.Item($intRow,1).Font.Bold = $True

    $intRow++

    $Sheet.Cells.Item($intRow,2) = "ServiceAccount"

    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $Sheet.Cells.Item($intRow,3) = "Displayname"

    $Sheet.Cells.Item($intRow,3).Font.Bold = $True

    $Sheet.Cells.Item($intRow,4) = "ServiceState"

    $Sheet.Cells.Item($intRow,4).Font.Bold = $True

    {

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' Out-Null

    $intRow++

    $managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState

    $Sheet.Cells.Item($intRow,2) = $managedcomputer.services.Name

    $Sheet.Cells.Item($intRow,3) = $managedcomputer.services.ServiceAccount

    $Sheet.Cells.Item($intRow,4) = $managedcomputer.services.DisplayName

    $Sheet.Cells.Item($intRow,5) = $managedcomputer.services.ServiceState

    }

    $intRow++

    }

    $Sheet.UsedRange.EntireColumn.AutoFit()

  • Duran (11/16/2015)


    ...The first bit of PS above the dashed line, gets me what I want but only on the local host, if I put in a FQDN of the remote computer, including the port number, it still only gives me the local host...

    Import-Module SQLPS -DisableNameChecking

    $InstanceName = "NAME OF REMOTE INSTANCE OF SQL SERVER"

    $folder = "H:\temp1"

    $currdate = Get-Date -Format "yyyy-MM-dd"

    $filename = "$($InstanceName)_ListServices_$($currdate).csv"

    $fullpath = Join-Path $folder $filename

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    #List Services

    $managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState |

    Export-Csv -Path $fullpath -NoTypeInformation

    #export result to csv

    explorer $folder

    #-----------------------------------------------------------------------------------------------------------------------

    ...

    It appears that you only use $InstanceName for $filename. From what I can see $managedcomputer is always the local machine as no machine is specified.

    Try the following change. Before:

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    After:

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $InstanceName

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Duran (11/16/2015)


    ...The piece of code I have after the line, I'm trying to get it to put all the output into an excel document, the excel document opens up and all the headers appear, but I cant work out what I am doing wrong, or what is missing, that is preventing the output from filling in the cells with the required info, I do not think the .TXT file is getting read either, I cant see what's missing to prevent that, the file is in place...

    #-----------------------------------------------------------------------------------------------------------------------

    Import-Module SQLPS -DisableNameChecking

    #Create a new Excel object using COM

    $Excel = New-Object -ComObject Excel.Application

    $Excel.visible = $True

    $Excel = $Excel.Workbooks.Add()

    $Sheet = $Excel.Worksheets.Item(1)

    $intRow = 1

    ForEach ($Instancename in Get-Content "H:\Documents\DevServers.txt")

    {

    #$managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    $intRow++

    #Create column headers

    $Sheet.Cells.Item($intRow,1) = "Name:" #$managedcomputer.Services

    $Sheet.Cells.Item($intRow,1).Font.Size = 12

    $Sheet.Cells.Item($intRow,1).Font.Bold = $True

    $intRow++

    $Sheet.Cells.Item($intRow,2) = "ServiceAccount"

    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $Sheet.Cells.Item($intRow,3) = "Displayname"

    $Sheet.Cells.Item($intRow,3).Font.Bold = $True

    $Sheet.Cells.Item($intRow,4) = "ServiceState"

    $Sheet.Cells.Item($intRow,4).Font.Bold = $True

    {

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' Out-Null

    $intRow++

    $managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState

    $Sheet.Cells.Item($intRow,2) = $managedcomputer.services.Name

    $Sheet.Cells.Item($intRow,3) = $managedcomputer.services.ServiceAccount

    $Sheet.Cells.Item($intRow,4) = $managedcomputer.services.DisplayName

    $Sheet.Cells.Item($intRow,5) = $managedcomputer.services.ServiceState

    }

    $intRow++

    }

    $Sheet.UsedRange.EntireColumn.AutoFit()

    Again, I cannot see where you are trying to set $managedcomputer to a different (remote) machine.

    Try the following change. Before:

    ForEach ($Instancename in Get-Content "H:\Documents\DevServers.txt")

    {

    #$managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'

    $intRow++

    #Create column headers

    $Sheet.Cells.Item($intRow,1) = "Name:" #$managedcomputer.Services

    $Sheet.Cells.Item($intRow,1).Font.Size = 12

    $Sheet.Cells.Item($intRow,1).Font.Bold = $True

    $intRow++

    $Sheet.Cells.Item($intRow,2) = "ServiceAccount"

    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $Sheet.Cells.Item($intRow,3) = "Displayname"

    $Sheet.Cells.Item($intRow,3).Font.Bold = $True

    $Sheet.Cells.Item($intRow,4) = "ServiceState"

    $Sheet.Cells.Item($intRow,4).Font.Bold = $True

    {

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' Out-Null

    $intRow++

    $managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState

    $Sheet.Cells.Item($intRow,2) = $managedcomputer.services.Name

    $Sheet.Cells.Item($intRow,3) = $managedcomputer.services.ServiceAccount

    $Sheet.Cells.Item($intRow,4) = $managedcomputer.services.DisplayName

    $Sheet.Cells.Item($intRow,5) = $managedcomputer.services.ServiceState

    }

    $intRow++

    }

    After:

    ForEach ($Instancename in Get-Content "H:\Documents\DevServers.txt")

    {

    $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $Instancename

    $intRow++

    #Create column headers

    $Sheet.Cells.Item($intRow,1) = "Name:" #$managedcomputer.Services

    $Sheet.Cells.Item($intRow,1).Font.Size = 12

    $Sheet.Cells.Item($intRow,1).Font.Bold = $True

    $intRow++

    $Sheet.Cells.Item($intRow,2) = "ServiceAccount"

    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $Sheet.Cells.Item($intRow,3) = "Displayname"

    $Sheet.Cells.Item($intRow,3).Font.Bold = $True

    $Sheet.Cells.Item($intRow,4) = "ServiceState"

    $Sheet.Cells.Item($intRow,4).Font.Bold = $True

    ForEach ($service in $managedcomputer.Services)

    {

    $intRow++

    $Sheet.Cells.Item($intRow,2) = $service.Name

    $Sheet.Cells.Item($intRow,3) = $service.ServiceAccount

    $Sheet.Cells.Item($intRow,4) = $service.DisplayName

    $Sheet.Cells.Item($intRow,5) = $service.ServiceState

    }

    }

    NOTE: I am working from memory as I have no PowerShell/SQL Server access where I am today.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Hi, thank you for your help, with your suggestions and a little tinkering, it has been wittled from 6 errors down to 1. I feel like I am almost at the top of the mountain here!!

    #$InstanceName= @()

    Import-Module SQLPS -DisableNameChecking

    $ManagedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $InstanceName

    #Create a new Excel object using COM

    $Excel = New-Object -ComObject Excel.Application

    $Excel.visible = $True

    $Excel = $Excel.Workbooks.Add()

    $Sheet = $Excel.Worksheets.Item(1)

    $intRow = 1

    ForEach ($Instancename in Get-Content "H:\Documents\DevServers.txt")

    {

    #$managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $InstanceName

    $intRow++

    #Create column headers

    $Sheet.Cells.Item($intRow,1) = "Name: " #$managedcomputer.Services"

    $Sheet.Cells.Item($intRow,1).Font.Size = 12

    $Sheet.Cells.Item($intRow,1).Font.Bold = $True

    $intRow++

    $Sheet.Cells.Item($intRow,2) = "ServiceAccount"

    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $Sheet.Cells.Item($intRow,3) = "Displayname"

    $Sheet.Cells.Item($intRow,3).Font.Bold = $True

    $Sheet.Cells.Item($intRow,4) = "ServiceState"

    $Sheet.Cells.Item($intRow,4).Font.Bold = $True

    #ForEach ($service in $ManagedComputer) #With this as is, I get the local hostname under 'ServiceAccount' and a host of errors

    ForEach ($services in $InstanceName) #with this the headers appear with no information. The cells remain empty.

    {

    $intRow++

    #$managedcomputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState

    $Sheet.Cells.Item($intRow,2) = $services.Name

    $Sheet.Cells.Item($intRow,3) = $services.ServiceAccount

    $Sheet.Cells.Item($intRow,4) = $services.DisplayName

    $Sheet.Cells.Item($intRow,5) = $services.ServiceState

    }

    #$intRow++

    }

    $Sheet.UsedRange.EntireColumn.AutoFit()

    $error[0]|format-list -force

    <#

    If I run as administator I still get the error...

    New-Object : Exception calling ".ctor" with "1" argument(s): "Invalid parameter "

    At H:\Documents\List_Service_Accounts_Works_SSC.ps1:20 char:20

    + $managedcomputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.managedcom ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException

    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    ...but the information appears in the console (not the spreadsheet), with one issue in which the service name appears under 'Name', rather than the server name.

    I've searched google for a number of hours, found things similar but not relevent to my situation, so I'm hoping other peoples hard-nosed experience might help me out here. I do however

    have a complete list of the error above thanks to $error[0]|format-list -force. Could be handy one day when I know more.

    Exception : System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "Invalid parameter " --->

    System.Management.ManagementException: Invalid parameter

    at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)

    at System.Management.ManagementPath.SetWbemPath(IWbemPath wbemPath, String path)

    at System.Management.ManagementPath.CreateWbemPath(String path)

    at System.Management.ManagementPath..ctor(String path)

    at Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer.GetManagementPath(String machineName)

    at Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer.Init(String machineName)

    at Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer..ctor(String machineName)

    --- End of inner exception stack trace ---

    at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[]

    originalArguments)

    at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)

    at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)

    TargetObject :

    CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException

    FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    ErrorDetails :

    InvocationInfo : System.Management.Automation.InvocationInfo

    ScriptStackTrace : at <ScriptBlock>, H:\Documents\List_Service_Accounts_Works_SSC.ps1: line 20

    PipelineIterationInfo : {}

    PSMessageDetails :

    #>

  • I'm curious to know why you are using SMO's WMI class to get service information? It is much easier to just use Get-Service or win32_service:

    Get-WmiObject win32_service | where {$_.DisplayName -match "SQL Server"} | select Name, DisplayName, State, StartName

    The advantage you have over this you can use the "-ComputerName" parameter for Get-WmiObject, and it accepts an array. So in your case all you need:

    $serverList = Get-Content 'H:\Documents\DevServers.txt' -Raw

    Get-WmiObject win32_service -ComputerName $serverList | where {$_.DisplayName -match "SQL Server"} | select PSComputerName, Name, DisplayName, State, StartName

    If you want to adjust the property names so the column name matches up to your spreadsheet you can adjust your select to this:

    select @{Label="ServerName";Expression={$_.PSComputerName}}, @{Label="ServiceAccount";Expression={$_.StartName}}, DisplayName, @{Label="ServiceState";Expression={$_.State}}

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Hi Shawn,

    Thank you for getting back, I have tried your code but I'm having trouble getting it to work, the last one that does the local machine works, but I am trying get the info from some remote machines, so I tried this...

    [/code]

    $serverList = Get-Content 'H:\Documents\DevServers.txt' #-Raw

    Get-WmiObject win32_service -ComputerName $serverList | where {$_.DisplayName -match "SQL Server"} | select PSComputerName, Name, DisplayName, State, StartName

    [/code]

    The result is...

    PS SQLSERVER:\> $serverList = Get-Content 'H:\Documents\DevServers.txt' #-Raw

    Get-WmiObject win32_service -ComputerName $serverList | where {$_.DisplayName -match "SQL Server"} | select PSComputerName, Name, DisplayName, State, StartName

    Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the

    command again.

    At line:2 char:43

    + Get-WmiObject win32_service -ComputerName $serverList | where {$_.DisplayName -m ...

    + ~~~~~~~~~~~

    + CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    ...I cant believe I'm having this much trouble getting what is probably basic information. I am also trying to get the account that is running the service.

    So are you saying I would be better to use Get-Service or Get-WMIObject? Which assemblies go with which. The other thing I am having trouble getting my head around is what assemblies I need to load depending on what I am doing at the time, is there a standard way of working that out?

    Regards,

    D.

  • What is the format of your server text file, DevServers.txt?

    Take 3 servers out of that list and just set them on the command line as:

    $serverList = 'Server1','Server2','Server3'

    Does that return any information?

    Get-Service can be used to get a quick status of a service, but is limited on what details of that service you can retrieve, that is where win32_service comes in. The service class, win32_service, gives you the information you see via the Services Management Console. So it is just based on what you want to do.

    Regarding assemblies, if you want to work with software or applications that are added to a Windows machine, you will generally need to load an assembly (e.g. SQL Server, Active Directory).

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Hi Shawn,

    At the moment, I have only listed one server in the txt file just for test purposes, and its basically..

    FQDN\Instance, port

    ...and that's it, when I add the others it will just be one under the other. Having done your suggestion, I am getting different result as previously...

    PS SQLSERVER:\> $serverList = 'FQDN\Instance,Port'

    Get-WmiObject win32_service -ComputerName where {$_.DisplayName -match "SQL Server"} |

    select ComputerName, Name, DisplayName, State, StartName

    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    At line:2 char:1

    + Get-WmiObject win32_service -ComputerName where {$_.DisplayName -match "SQL Serv ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException

    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    ...At first I thought that it might be that WMI was not around with SQL 2000 (which are the remote servers I am trying to get the info from), but read that SMO is fully compatible for SQL 2000 onwards. Thank you again for your help on this. I'll have to take a look into the RPC issue now.

    Regards,

    D.

  • At the moment, I have only listed one server in the txt file just for test purposes, and its basically..

    FQDN\Instance, port

    You have to provide the server name only with the "-ComputerName" parameter for Get-WmiObject or Get-Service. You will only need the instance and port number for connecting to the SQL Server using SMO.

    Your text file should just have the FQDN.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Hi Shawn

    AH! I literally found this out just as I got your reply through, and then it was by accident! So now I have...

    Get-Service -ComputerName $ComputerName -Name SQL*

    Format-Table -AutoSize

    ...the only thing I need to try to get as well is the server account to appear.

    Not having the instance and port for -computername is one if those things I'll now remember forever!

    Regards,

    D.

Viewing 15 posts - 1 through 15 (of 22 total)

You must be logged in to reply to this topic. Login to reply