-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSet-FolderIcon.ps1
More file actions
104 lines (102 loc) · 2.8 KB
/
Set-FolderIcon.ps1
File metadata and controls
104 lines (102 loc) · 2.8 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<#
.SYNOPSIS
This function sets a folder icon on specified folder.
.DESCRIPTION
This function sets a folder icon on specified folder. Needs the path to the icon file to be used and the path to the folder the icon is to be applied to. This function will create two files in the destination path, both set as Hidden files. DESKTOP.INI and FOLDER.ICO
.EXAMPLE
Set-FolderIcon -Icon "C:\Users\Mark\Downloads\Radvisual-Holographic-Folder.ico" -Path "C:\Users\Mark"
Changes the default folder icon to the custom one I donwloaded from Google Images.
.EXAMPLE
Set-FolderIcon -Icon "C:\Users\Mark\Downloads\wii_folder.ico" -Path "\\FAMILY\Media\Wii"
Changes the default folder icon to custom one for a UNC Path.
.EXAMPLE
Set-FolderIcon -Icon "C:\Users\Mark\Downloads\Radvisual-Holographic-Folder.ico" -Path "C:\Test" -Recurse
Changes the default folder icon to custom one for all folders in specified folder and that folder itself.
.NOTES
Created by Mark Ince on May 4th, 2014. Contact me at mrince@outlook.com if you have any questions.
#>
function Set-FolderIcon
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
Position=0)]
[string[]]$Icon,
[Parameter(Mandatory=$True,
Position=1)]
[string]$Path,
[Parameter(Mandatory=$False)]
[switch]
$Recurse
)
BEGIN
{
$originallocale = $PWD
#Creating content of the DESKTOP.INI file.
$ini = '[.ShellClassInfo]
IconFile=folder.ico
IconIndex=0
ConfirmFileOp=0'
Set-Location $Path
Set-Location ..
Get-ChildItem | Where-Object {$_.FullName -eq "$Path"} | ForEach {$_.Attributes = 'Directory, System'}
}
PROCESS
{
$ini | Out-File $Path\DESKTOP.INI
If ($Recurse -eq $True)
{
Copy-Item -Path $Icon -Destination $Path\FOLDER.ICO
$recursepath = Get-ChildItem $Path -r | Where-Object {$_.Attributes -match "Directory"}
ForEach ($folder in $recursepath)
{
Set-FolderIcon -Icon $Icon -Path $folder.FullName
}
}
else
{
Copy-Item -Path $Icon -Destination $Path\FOLDER.ICO
}
}
END
{
$inifile = Get-Item $Path\DESKTOP.INI
$inifile.Attributes = 'Hidden'
$icofile = Get-Item $Path\FOLDER.ICO
$icofile.Attributes = 'Hidden'
Set-Location $originallocale
}
}
<#
#>
function Remove-SetIcon
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
Position=0)]
[string]$Path
)
BEGIN
{
$originallocale = $PWD
$iconfiles = Get-ChildItem $Path -Recurse -Force | Where-Object {$_.Name -like "FOLDER.ICO"}
$iconfiles = $iconfiles.FullName
$inifiles = Get-ChildItem $Path -Recurse -Force | where-Object {$_.Name -like "DESKTOP.INI"}
$inifiles = $inifiles.FullName
}
PROCESS
{
Remove-Item $iconfiles -Force
Remove-Item $inifiles -Force
Set-Location $Path
Set-Location ..
Get-ChildItem | Where-Object {$_.FullName -eq "$Path"} | ForEach {$_.Attributes = 'Directory'}
}
END
{
Set-Location $originallocale
}
}