I am having an issue with passing variables to a remote powershell session and I've searched everywhere on the internet I can think of so I'm hoping someone out there can help. I have a function calling a job which is telling it to start a scriptblock
What I'm trying to do is write a script to allow me to failover clusters from one VM. It works fine if everything is hardcoded but that means I have to change the script for every failover and that just won't save me anytime at all.
$Computer = Server1
$Clustergrp = Cluster1
function FAILOVER(){
$job = Start-Job -scriptblock $JobScript
do {[System.Windows.Form.Application]::DoEvent() } until ($Job.State -eq "Completed")
$JobScript =
{
Invoke-Command -ComputerName $using:Computer -ScriptBlock {Move-ClusterGroup -Name $using:Clustergrp}
}
What am I missing here? Help please!
I've tried using arguments and $using:variable but nothing seems to work. Yet if I hardcode everything in the scriptblock it works everytime.
I've also tried just using -ComputerName $Computer -ScriptBlock{.....}
but that didn't work either.