Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Poweshell script error: the term 'import-module' is not recognized as the name of a cmdlet, function, script file, or operable program.

$
0
0

I am getting below error when executing a powershell script from sql agent job on a SQL Server 2008 R2 failover cluster. This code executed OK on other sql servers. Code runs fine when executed through powershell directly as well.  The agent service and sql server service account are sysadmins on the box.

"A job step received an error at line 111 in a PowerShell script. The corresponding line is ' { import-module failoverclusters -ErrorAction SilentlyContinue '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The term 'import-module' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. "

# if this is a two-node windows 2008 R2 failover cluster set $iscluster = "TRUE"

$iscluster = "TRUE"

if ($isCluster  -eq “TRUE” )
 { import-module failoverclusters -ErrorAction SilentlyContinue
   $nodes = get-clusterNode |select-object -ExpandProperty name
   $node1  = $Nodes[0]
   If ($nodes.count -gt 1) {$node2  = $Nodes[1]}
   $clusterName = get-cluster |select-object -ExpandProperty name
  }
 #cluster name is irrelevent. Treat  $strComputerName same as $clusterName
else {$clusterName = $strComputerName    }

I am basically trying to get the cluster name, and the nodes' names. If there is  an easy workaround get that information I will accept t as an answer. 

sys.dm_os_cluster_nodes provides only the individual node names not cluster name.



Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>