I would like to run a few lines of code on a remote machine, so I have to use the "Invoke-command" cmdlet to achieve that. The script I want to run is rather long (not just a simple command, but a few loops, conditionals, etc.), so it is not possible to just copy the codes in-line. So can anyone teach me the syntax for doing that?
for example: I have the following code:
Function createDict(){
$Dict = @{}
$Variables = Get-Content .\Variables.ini.
foreach ($str in $Variables){
if ($str -eq ""){
continue
}
if ($str.StartsWith("[") -or $str.StartsWith("#")){
continue
} else {
$Pair = $str.Split('=')
$Dict.Add($Pair[0], $Pair[1])
}
}
return $Dict
}
Import-Module virtualmachinemanager
stop-VM NHQA-W8-64b-Q13
start-VM NHQA-W8-64b-Q13
You dont need to try to understand the above code, I just want to show you what kind of things that I am trying to execute on the remote machine here. Thank you very much in advance!