To get the script to work on my PC I had to do these things
- the multi line comments at the top gave errors, but changing /* and */ to <# and #> fixed that.-Nod5
Ooops, my bad, I added the comment after pasting into the post ... should've tested it.
I've updated the code/archive.
- run the cmd window as administrator
- add the Bypass argument, like so
Wasn't necessary if run from a PowerShell console, even just right-click on the script and choose
Run with Powershell but you'd bump up against the ExecutionPolicy restriction - which does get to be a real PITA sometimes. In theory you can right-click->
Properties and select something like
Trust this file under the Security tab ... but I haven't seen it for awhile so I may be mis-remembering.
Shouldn't need Admin privileges since you're only writing to a directory that the user owns anyway ... just tried it here, no Admin required, just had to answer '(Y)es' to the ExecutionPolicy question that pops up.
The same task can also be created manually (and deleted if no longer needed) through the Task Scheduler (win+I and search for "schedule tasks").
Not a very end-user friendly way to set this up though.
Perhaps this
post which shows setting/deleting a scheduled task in Powershell may help?
Give the task a static name and have the script just check if it's there at each run using
schtasks /query <taskname>, implement if it isn't and have an optional argument to the script
Apps2Shortcut.ps1 -Remove to remove it if the task is no longer required.