locked
Newbie PowerShell Questions RRS feed

  • Question

  • Hello All,

    I'm a database administrator and after attending several sessions on PowerShell for DBAs on the latest convention I attended (SQL PASS), I decided to adopt PowerShell and I'm starting to use this for some of my daily tasks.

    I'm a complete newbie, so bear with me.

    Currently, I'm looking for a way to get Cluster related information from the 7 clusters I manage.

    My goal is to create a script that will pull information from clusters after our patching/outage weekend. The information from this script will be stored in a database and presented over SSRS (SQL Server Reporting Services). The report should tell us what node of the cluster own which resources so we can move resources around.

    I think the Get-Cluster* cmdlets will provide me the information I need. I'm just having trouble executing them, storing them and passing different values to them. Can you guys help me out?

    First, I need to be able to execute the Get-Cluter commands. I can only do that from a cluster. Why is that? Can I run this command from a server that is not a cluster? Do I need to install anything on my Win 2008 R2 box?

    I also need to be able to pass a server name to my command. This way I can loop through a list of server names.

    I need to store the results in a file temporarily before loading them to a database table.

     

    Issues that I'm having:

    I can't get to import the FailoverClusters module. Perhaps because I don't have the Cluster Feature installed? I'm running this from a VM, so I can't install a cluster on a VM. There a way to install something that will allow me to run the Get-Cluster commandlets?

    PS V:\> Import-Module FailoverClusters
    Import-Module : The specified module 'FailoverClusters' was not loaded because no valid module file was found in any mo
    dule directory.
    At line:1 char:14
    + Import-Module <<<<  FailoverClusters
        + CategoryInfo          : ResourceUnavailable: (FailoverClusters:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    PS V:\>

    This is what I see when I run Get-Module:

    PS V:\> Get-Module

    ModuleType Name                      ExportedCommands
    ---------- ----                      ----------------
    Manifest   ADRMS                     {Uninstall-ADRMS, Update-ADRMS, Install-ADRMS}
    Manifest   AppLocker                 {Get-AppLockerPolicy, Get-AppLockerFileInformation, Test-AppLockerPolicy...
    Manifest   BestPractices             {Get-BpaModel, Set-BpaResult, Invoke-BpaModel, Get-BpaResult}
    Manifest   BitsTransfer              {Start-BitsTransfer, Remove-BitsTransfer, Resume-BitsTransfer, Get-BitsT...
    Script     PSDiagnostics             {Enable-PSTrace, Enable-WSManTrace, Start-Trace, Disable-PSWSManCombined...
    Manifest   ServerManager             {Remove-WindowsFeature, Get-WindowsFeature, Add-WindowsFeature}
    Manifest   TroubleshootingPack       {Get-TroubleshootingPack, Invoke-TroubleshootingPack}

    Let me know if there's any other information I can provide to help you helping me on this request and thanks in advance for the help.


    --- Best Regards, Igor Santos - DBA igor.santos@citrix.com
    Tuesday, December 21, 2010 5:51 PM

Answers

  • I don't think you can.  I did some testing from my Exchange servers (they use clustering for the DAGs, albeit in a rather limited fashion), and get-cluster appears to rely on the cluster service running on the local server to get it's information.  It seems the cmdlet needs to be run from a member of the cluster.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Tuesday, December 21, 2010 8:08 PM
  • That's correct the failoverclusters module requires Windows 2008 R2 cluster service install on the box from which is is run. In my environment which is mostly Windows 2003 clusters, I use WMI to retrieve cluster information. Using WMI means you do not need to rely on the cluster service. I've posted my cluster functions on PoshCode

    Save the code as LibraryMSCS.ps1 and source the file

    . ./libraryMSCS.ps1

    You should then be able to use the functions to retrieve information about cluster, groups and resources.

    http://poshcode.org/2420

    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Thursday, December 23, 2010 10:08 PM
  • That's right. In order to use the failovercluster module, you need to install FailOver Clustering Feature.

    http://technet.microsoft.com/en-us/library/ee619762(WS.10).aspx

    Regards,

    Manoj R. Nair

    MCT

    http://blogs.technet.com/manojnair


    Cheers, MN
    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Saturday, December 25, 2010 4:18 PM

All replies

  • get-module will show you information about the modules you have loaded.

    get-module -listavailable will show you all the available modules you have installed that can be loaded.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Tuesday, December 21, 2010 6:06 PM
  • Thank you MJolinor.

    Below are the results from the command you specified. How can I make FailoverClusters available on this list?

     

     

    PS V:\> get-module -listavailable

    ModuleType Name                      ExportedCommands
    ---------- ----                      ----------------
    Script     adoLib                    {}
    Manifest   Agent                     {}
    Script     ISECreamBasic             {}
    Script     OracleClient              {}
    Script     OracleIse                 {}
    Script     PBM                       {}
    Script     PerfCounters              {}
    Manifest   Repl                      {}
    Manifest   ShowMbrs                  {}
    Script     SQLIse                    {}
    Manifest   SQLMaint                  {}
    Manifest   SQLParser                 {}
    Script     SQLProfiler               {}
    Script     SQLPSX                    {}
    Manifest   SQLServer                 {}
    Manifest   SSIS                      {}
    Manifest   WPK                       {}
    Manifest   ADRMS                     {}
    Manifest   AppLocker                 {}
    Manifest   BestPractices             {}
    Manifest   BitsTransfer              {}
    Manifest   PSDiagnostics             {Enable-PSTrace, Enable-WSManTrace, Start-Trace, Disable-PSWSManCombined...
    Manifest   ServerManager             {}
    Manifest   TroubleshootingPack       {}


    --- Best Regards, Igor Santos - DBA igor.santos@citrix.com
    Tuesday, December 21, 2010 7:27 PM
  • I don't think you can.  I did some testing from my Exchange servers (they use clustering for the DAGs, albeit in a rather limited fashion), and get-cluster appears to rely on the cluster service running on the local server to get it's information.  It seems the cmdlet needs to be run from a member of the cluster.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Tuesday, December 21, 2010 8:08 PM
  • That's correct the failoverclusters module requires Windows 2008 R2 cluster service install on the box from which is is run. In my environment which is mostly Windows 2003 clusters, I use WMI to retrieve cluster information. Using WMI means you do not need to rely on the cluster service. I've posted my cluster functions on PoshCode

    Save the code as LibraryMSCS.ps1 and source the file

    . ./libraryMSCS.ps1

    You should then be able to use the functions to retrieve information about cluster, groups and resources.

    http://poshcode.org/2420

    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Thursday, December 23, 2010 10:08 PM
  • That's right. In order to use the failovercluster module, you need to install FailOver Clustering Feature.

    http://technet.microsoft.com/en-us/library/ee619762(WS.10).aspx

    Regards,

    Manoj R. Nair

    MCT

    http://blogs.technet.com/manojnair


    Cheers, MN
    • Marked as answer by Dale Qiao Monday, December 27, 2010 1:02 AM
    Saturday, December 25, 2010 4:18 PM
  • I'm definitelly going to go with the WMI solution.

    Please send me any resources or suggestions you guys have on this.

    Thank you very much for the help on this problem, I really appreciate it.


    --- Best Regards, Igor Santos - DBA igor.santos@citrix.com
    Monday, December 27, 2010 4:45 PM
  • Hey Chad,

    How are you? I watched Aaron Nelson's (SQLVariant.com) session on PowerShell for DBA this year at SQL PASS in Seattle and he mentioned your name. Glad to see you replying on my post.

    Do I need to source the file everytime I have to use it?

    If I want to run Get-ClusterNode for instance, should I run it like this:

    Get-ClusterNode "ClusterName"

    I'm getting the error message below when I run the code above:

    Get-WmiObject : Access denied
    At D:\PowerShell\Scripts\libraryMSCS.ps1:38 char:9
    +     gwmi <<<<  -class MSCluster_Node -namespace "root\mscluster" -computername $cluster | add-member -pass NoteProper
    ty Cluster $cluster
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    I'm a local admin on the machine where I'm running this code and a local admin on the destination as well.

    Where's the access denied message from?

    Thanks for the help.


    --- Best Regards, Igor Santos - DBA igor.santos@citrix.com
    Monday, December 27, 2010 6:54 PM
  • It worked when I ran the cmdlet against a 2003 cluster.

    Let me do some digging and play around with this now. Thanks.


    --- Best Regards, Igor Santos - DBA igor.santos@citrix.com
    Monday, December 27, 2010 7:23 PM
  • It worked for me a against a Windows 2008 R2 cluster as well as Windows 2003. After some further testing I noticed a small issue with some of the add-member properties not returning and I posted an updated script:

    http://poshcode.org/2426

     

    Minor issue, though. Usually when I receive Access Denied errors it has something to do with rights or firewalls. I would suggest just running the simplest command as test without full functions...

    $cluster = 'myclustername'

     gwmi - class "MSCluster_Cluster" -namespace "root\mscluster" -computername $cluster

     


    Friday, December 31, 2010 3:24 AM
  • After the cluster is installed, you have to run an 'importsystemmodules'.  Then you get the Add and Get and Clusters.
    Friday, March 11, 2011 7:31 PM