Skip to content

Commit 3d4ac30

Browse files
committed
Added Add-ToStartup
1 parent 7b08d12 commit 3d4ac30

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

system-setup/Add-ToStartup.ps1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Add-ToStartup {
2+
<#
3+
.SYNOPSIS
4+
Script for adding items to system startup
5+
6+
.DESCRIPTION
7+
With this cmdlet you can add items to startup. You can add items for a current user or computer/all users
8+
9+
.PARAMETER ItemPath
10+
Specifies the path to an item.
11+
12+
.PARAMETER ComputerConfiguration
13+
Specifies whether item should be added to the computer/all users startup folder
14+
15+
.EXAMPLE
16+
Add-ToStartup -ItemPath C:\Windows\System32\notepad.exe
17+
This command shows how to add 'notepad.exe' program to Startup.
18+
19+
.EXAMPLE
20+
Add-ToStartup -ComputerConfiguration -ItemPath C:\Windows\System32\notepad.exe
21+
This command shows how to add 'notepad.exe' program to Startup for computer/all users
22+
#>
23+
[Cmdletbinding(SupportsShouldProcess = $true)]
24+
Param
25+
(
26+
[Parameter(Mandatory = $true, Position = 0)]
27+
[Alias('p')][String]$ItemPath,
28+
[Parameter(Mandatory = $false, Position = 1)]
29+
[Alias('cc')][Switch]$ComputerConfiguration
30+
)
31+
32+
If (Test-Path -Path $ItemPath) {
33+
If ($ComputerConfiguration) {
34+
$ComputerConfigDestination = "$env:ALLUSERSPROFILE\Microsoft\Windows\Start Menu\Programs\StartUp"
35+
Copy-Item -Path $ItemPath -Destination $ComputerConfigDestination
36+
}
37+
Else {
38+
$UserConfigDestination = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
39+
Copy-Item -Path $ItemPath -Destination $UserConfigDestination
40+
}
41+
}
42+
Else {
43+
Write-Warning "The path does not exist, plese input the correct path."
44+
}
45+
}

0 commit comments

Comments
 (0)