Copy and paste the above snippet into a txt file, rename it "myscript.ps1" and right click to run it.
Right click > select > 'Run with Powershell'
Or am I mis-taking your intent.
Don't forget to mark your posts as answered so they drop off the unanswered post filter. If I've helped you and you want to show your gratitude, just click that green thingy.