Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Start-WebAppPool Remotely -Name Variable is sent as $Null

$
0
0

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.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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