I have a scheduled PowerShell script I want to run on the current owner node of a specific failover cluster role.
I am trying to use a scheduled PowerShell task, to firstly interrogate the cluster, and then based on the owner node of the role, connect and run a remote PowerShell script on that node.
Here is what I have thus far:
$Role = Get-ClusterGroup -Cluster FLX-CL-CL01.cory.local -Name FLX-CL-FS01
$OwnerNode = $Role.OwnerNode
$OwnerNodeName = $OwnerNode.Name
$Credential = Get-Credential
$Session = New-PSSession -ComputerName $OwnerNodeName -Credential
$Credential
Invoke-Command -Session $Session -ScriptBlock {
powershell.exe -Command "\\path_to_script.ps1"
}
Remove-PSSession -Session $Session
When running this, I get an access is denied error, but I am not really clear on what access is denied to?
I did try putting the script in without specifying powershell.exe -Command
, but it says an error occurred while creating the pipeline. If I put it in quotes, it just outputs the path as text.
Can anyone advise what syntax I should be using within the -ScriptBlock
section to execute this script on the remote machine?
Managed to work this out, by removing -scriptblock, and replacing with -FilePath and followed by the path to the script.