I was given a list of 200 or so webpages so I could create shortcuts. Not just any old shortcut, but they needed to contain an argument to tell the browser to open a URL in full-screen kiosk mode. This is so that the user cannot immediately exit the page; beneficial for controlled environments and public portals.
After creating- I don’t know- twelve shortcuts; I thought, there has to be an easy way to do this.
It wasn’t too bad, just.. cumbersome.
It could be scripted, I thought.
I made the determination that I could create a function which is looped for each entry in a CSV input file.
So, I’m creating a CSV file with the following structure:
name,url
For example:
Google,https://google.com YouTube,https://youtube.com GitHub,https://github.com
I’m calling this input.csv and I’ll put it in a new folder C:\script for example.
Then, I’ll open PowerShell ISE (or just plain ‘ol notepad) and save a new .ps1 file to my working directory C:\script
1. Define parameters:
$destination = 'F:\destination' ### where do you want the shortcuts to be created? $chromeroot = 'C:\Program Files (x86)\Google\Chrome' ### since I am creating chrome shortcuts, I need the path to the install directory. $workingdir = 'C:\script' ### I'm defining a working directory -- This is where I keep the CSV and the PS1 files. I guess I don't need to define this... $input = Import-Csv .\input.csv ### define the source CSV file which contains your data
2. Create a function that creates this specialized shortcut.
I’m calling this function “Create-Shortcut” for obvious reasons.
function Create-Shortcut { $Shell = New-Object -ComObject ("WScript.Shell") $ShortCut = $Shell.CreateShortcut("$destination\$URLTitle.lnk") $ShortCut.TargetPath="$chromeroot\Application\chrome.exe" $ShortCut.Arguments="--kiosk $URL" $ShortCut.WorkingDirectory = "$chromeroot\Application"; $ShortCut.WindowStyle = 1; $ShortCut.IconLocation = "$chromeroot\Application\chrome.exe, 0"; $ShortCut.Description = ""; $ShortCut.Save() }
A few notes:
- You can change the icon by defining an alternate path to an icon
- You can optionally tweak the script to add a description for each shortcut in Windows
- You don’t have to use the
--kiosk
argument!
2.5 Look into other chrome.exe arguments:
For example:
--no-referrers
--disable-background-mode
--incognito
--disable-plugins
3. Create a ForLoop
Here we are looking in the input.csv file for:
- the name
- the url
and we are running our function Create-Shortcut with the data parsed from the CSV.
ForEach ($item in $input){ $URLTitle = $($item.name) $URL = $($item.url) Create-Shortcut }
That’s it!
Check your destination folder and look at all those pretty new shortcuts.
All together:
### Use this tool to import a CSV of URLs to full-screen chrome shortcuts ### Tyler Woods (2016) ### CSV headers: name,url ### example GitHub,https://github.com $destination = 'F:\destination' $chromeroot = 'C:\Program Files (x86)\Google\Chrome' $workingdir = 'C:\script' $input = Import-Csv .\input.csv function Create-Shortcut { $Shell = New-Object -ComObject ("WScript.Shell") $ShortCut = $Shell.CreateShortcut("$destination\$URLTitle.lnk") $ShortCut.TargetPath="$chromeroot\Application\chrome.exe" $ShortCut.Arguments="--kiosk $URL" $ShortCut.WorkingDirectory = "$chromeroot\Application"; $ShortCut.WindowStyle = 1; $ShortCut.IconLocation = "$chromeroot\Application\chrome.exe, 0"; $ShortCut.Description = ""; $ShortCut.Save() } ForEach ($item in $input){ $URLTitle = $($item.name) $URL = $($item.url) Create-Shortcut }
0 Comments