Its neater to use the 'csw' current controlled switch device, because you don't have to hookup wires to control terminals for it. For both it and 'sw' you have to supply a .model command to define the switch characteristics.
N.B. 'csw' is slightly nonintuitive to use - fill in the name of the controlling voltage source on the SpiceModel attribute line and the name of the switch model (from the .model command) on the Value line. Blame the authors of the original Berkeley SPICE for the inverted attribute order. If the named voltage source's value is 0, it acts as a pure current probe.
N.B. the current through a voltage source driven by that source has opposite sign to the source's voltage. To control a 'csw' with minimum parts, set the internal resistance of the controlling voltage source to -1 and ground both terminals so it converts voltage into current of the same magnitude and sign.
I attach Cswitch.asc, which is a 'csw' example analogous to L.T's supplied 'sw' example: examples\Educational\Vswitch.asc
You can also use a
behavioural resistor in terms of time, which may be easier for very simple switching events. Edit the value to R=<expression> e.g:
R=if((time>1)&(time<2)), 1u, 1G)
which is on (one microohm) from time 1 second to 2 seconds, and off, (one gigaohm) the rest of the time. You can even use the 'csw' symbol for a behavioural resistor - simply change the prefix to R before you make any other changes then close and reopen the dialog.