Looking for powershell script

  • Cheers Rob,

    Ill do as you suggested.

    Thanks once again.

  • Hi Rob,

    I created another post in adminstration name (finding cluster nodes), i tried $server = ClusterNodes, but it is not working. can give some idea.

    Cheers,

  • Hi Rob,

    I created another post in adminstration name (finding cluster nodes), i tried $server = ClusterNodes, but it is not working. can give some idea.

    Cheers,

  • Hi Rob,

    I am sorry to asking you again,

    I need your help now, below code executing fine now on any server, but the issue is i need to store those values in sql table for monitoring. we have inhouse monitoring tool, so we are updating these changes to monitoring tool, but the issue is need to save these executed powershell values to sql table. i need to insert into table and update everytime. i need to run this on main server to get rest of servers information. it is kind of loop, every time audit updates it needs to update. can you please arrange my code into that way, because i have no idea. i'll be very greatfull if you can help.

    param(

    [string]$servers = $( Read-Host "Input server, please" )

    )

    foreach($server in $servers)

    {

    $SSRS = Get-Service -ComputerName $server -name *report*

    $SSIS = Get-Service -ComputerName $server -name *MSDts*

    $SSAS = Get-Service -ComputerName $server -name *Olap*

    $cluster = Get-Service -ComputerName $server -name *ClusSvc*

    $SQLbrowser = Get-Service -ComputerName $server -name *sqlbrowser*

    $SQLagent = Get-Service -ComputerName $server -name *serveragent*

    If ($SSRS -eq $null)

    {

    Write-Host "SSRS Service Not Running on $server"

    }

    else

    {

    $SSRS

    }

    If ($SSIS -eq $null)

    {

    Write-Host "SSIS Service Not Running on $server"

    }

    else

    {

    $SSIS

    }

    If ($SSAS -eq $null)

    {

    Write-Host "SSAS Service Not Running on $server"

    }

    else

    {

    $SSAS

    }

    If ($SQLbrowser -eq $null)

    {

    Write-Host "SQLbrowser Service Not Running on $server"

    }

    else

    {

    $SQLbrowser

    }

    If ($SQLagent -eq $null)

    {

    Write-Host "SQLagent Service Stopped on $server"

    }

    else

    {

    $SQLagent

    }

    If ($cluster -eq $null)

    {

    Write-Host "cluster Service Not running on $server"

    }

    else

    {

    $cluster

    }

    # Load SMO extension

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null;

    $srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server;

    # Get server properties

    $properties = $srv.Properties

    $owner_node = $properties.Item("ComputerNamePhysicalNetBIOS").Value;

    $is_clustered = $properties.Item("IsClustered").Value

    if($is_clustered)

    {

    Write-Host "The current active node of $server is $owner_node.";

    }

    else

    {

    Write-Host "$server is not a clustered instance of SQL Server.";

    }

    }

    Many Thanks

  • Hi

    You are probably best of using the Out-Datatable and Write-DataTable functions to do this.

    Google will give you plenty of examples

    https://blog.robsewell.com Its where I blog
    SQL Community Slack Channel https://sqlps.io/slack
    The Best PowerShell Module for the Modern SQL DBA https://dbatools.io
    Data South West User Group http://sqlsouthwest.co.uk/[/url]

Viewing 5 posts - 16 through 19 (of 19 total)

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