Strictly speaking (writing) the circuit below does what you describe, but it probably doesn't work in your application.

Would you please tell us more about what you want to do.

What do you want for an end result?
How many volts?
How many amps?
How often (frequency/dutycycle)?
Where does the signal that controls the switch come from and electrically, what does that signal look like?