When I do this:
$Server = Read-Host "Enter Web Server Name"
$AppPool = Read-Host "Enter Application Pool to Restart"
Invoke-command -ComputerName $Server -ScriptBlock { Stop-WebAppPool -Name $AppPool }
I get this:
Cannot validate argument on parameter 'Name'. The argument is null. Supply a non-null argument and try the command again.
I'm guessing it has to with something like variable scoping.. I've seen a few examples of how to do this but the level of scripting in their examples is beyond me.
This works for instance:
Invoke-command -ComputerName myComputerName -ScriptBlock { Stop-WebAppPool -Name RemoteTransfer }
but when I Read-Host and put in the extra {} in the ScriptBlock, my variable goes bye bye.
Thanks in advance.