Exercise 2: Why $serviceName Isn't Visible Remotely Without $using: — Possible Solution ==================================================================== WHY THE REMOTE SCRIPT BLOCK CAN'T SEE $serviceName ------------------------------ Per this chapter, a remote script block passed to Invoke-Command runs in a completely separate process on a completely separate machine - it has no visibility into local variables by default, no matter how clearly they were defined in the calling session just before the call. $serviceName exists only in the local PowerShell session's own scope; the remote machine has never heard of it and has no automatic way to see it, since the two are running as genuinely separate processes on separate computers, not sharing memory or scope in any way. WHY $using: FIXES IT ------------------------------ $using:serviceName is the explicit signal telling PowerShell to reach back into the local session, grab the current value of $serviceName, and inject that value into the remote script block before it runs - per this chapter, without this explicit signal, the remote script block only ever sees its own, entirely empty, local scope, which is why $serviceName would come back $null (or cause an error) rather than "Spooler". WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that the remote script block runs in a genuinely separate process with no automatic access to the local session's variables, and correctly explains that $using: is what explicitly bridges that gap by injecting the local value in.