-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-Internet-Shortcuts.ps1
More file actions
72 lines (58 loc) · 2.56 KB
/
Create-Internet-Shortcuts.ps1
File metadata and controls
72 lines (58 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<#
.SYNOPSIS
This small script is designed to take a list of destinations, and create shortcuts.
Author: Tony Habeger (github.com/selectfromt @TonyHabeger)
Version: 1.0
#>
# List of web links to create shortcuts for (http://,https://, or similar qualifier is required to prevent errors):
$destinationPaths = 'https://google.com/','https://microsoft.com','http://amazon.com'
# Function to pull registry values
function Get-RegistryValue{
param(
[parameter(Mandatory=$true)]
[string]
$subKeyValue,
[parameter(Mandatory=$true)]
[string]
$baseKeyValue,
[parameter(Mandatory=$true)]
[string]
$subValueName
)
# Set registry hive and subkeys
$registry = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::$baseKeyValue, [Microsoft.Win32.RegistryView]::Default)
$registryKey = $registry.OpenSubKey($subKeyValue)
# Get key value
$keyValue = $registryKey.GetValue($subValueName)
return $keyValue
}
# Take default browser setting and set the icon image as the default browser's icon
$browserIcon = (Get-RegistryValue -baseKeyValue "CurrentUser" -subKeyValue "SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice" -subValueName "ProgId")
switch -wildcard ($browserIcon){
("*chrome*"){
$browserIconPath = Get-RegistryValue -baseKeyValue "LocalMachine" -subKeyValue "SOFTWARE\\Classes\\ChromeHTML\\Application" -subValueName "ApplicationIcon"
$browserIconPath = $browserIconPath.split(",")[0]
}
("*edge*"){
$browserIconPath = Get-RegistryValue -baseKeyValue "LocalMachine" -subKeyValue "SOFTWARE\\Classes\\MSEdgeHTM\\Application" -subValueName "ApplicationIcon"
$browserIconPath = $browserIconPath.split(",")[0]
}
}
# Itterate through the destination paths and create a shortcut for each one.
foreach($destinationPath in $destinationPaths)
{
if($destinationPath -imatch '/'){
$linkName = $destinationPath.Split('/')[2].replace('.','-') + '.lnk'
}
else{
$linkName = $destinationPath.replace('.','-') + '.lnk'
}
# Creation of the shortcut
$shortcutPath = $env:HOMEDRIVE + $env:HOMEPATH + '\Desktop\' + $linkName
# Invoke WScript to assist in creation.
$WScriptShell = New-Object -ComObject WScript.Shell
$shortcut = $WScriptShell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $destinationPath
$shortcut.IconLocation = $browserIconPath
$shortcut.Save()
}