-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMake-BuildWindow.ps1
More file actions
64 lines (54 loc) · 2.16 KB
/
Make-BuildWindow.ps1
File metadata and controls
64 lines (54 loc) · 2.16 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
<#
.SYNOPSIS
Create a Powershell shortcut at the specified location.
.DESCRIPTION
Create a PowerShell shortcut at the specified location.
If a command has been specified, then it shall be executed before the user gets
control of the window.
The window shall not be closed at the termination of this program.
.PARAMETER CreationPath
[Required, String]
Absolute path of the location where the new PowerShell shortcut will be created.
Throw a System.IO.IOException if the path is invalid.
.PARAMETER Name
[Required, String]
Name of the new PowerShell shortcut.
.PARAMETER
.PARAMETER Command
[Optional, String]
PowerShell command to execute after opening a new PowerShell window but before
turning control over to the user.
Be sure to use ('') instead of ("") within the command, if necessary.
.EXAMPLE
MakeBuildWindow.ps1 -CreationPath "C:\Users\UserId\Desktop" -Name "Test"
--> Create a PowerShell shortcut called Test.lnk at C:\Users\UserId\Desktop.
MakeBuildWindow.ps1 -CreationPath "C:\Users\UserId\Desktop" -Name "Test" -Command "cd 'C:\Users\UserId'"
--> Create a PowerShell shortcut called Test.lnk at C:\Users\UserId\Desktop.
When the user clicks on the shorcut, Windows will open a PowerShell window
and execute "cd C:\Users\UserId" before turning control over to the user.
#>
[CmdletBinding(DefaultParameterSetName = 'Default')]
Param(
[Parameter(Mandatory = $True)]
[string]
[ValidateScript({
if (!(Test-Path $_)) {
throw [System.IO.IOException] "`"$_`" is an invalid location."
}
else {
return $True
}
})]
$CreationPath,
[Parameter(Mandatory = $True)]
$Name,
[string]
$Command
)
# Construct the PowerShell startup command based on user inputs.
if ($Command) {
$Command = "-noexit -command `"" + $Command + "`""
}
# Create a shortcut at $CreationPath. The shortcut will refer to
# $TargetPath (location of powershell.exe).
& "$PSScriptRoot\Create-Shortcut.ps1" -CreationPath $CreationPath -ShortcutName $Name -TargetPath $($PsHome + "\powershell.exe") -TargetArgs $Command