Last active
February 7, 2025 04:37
-
-
Save realChrisDeBon/f565a11f148b0638af26ab547ba87370 to your computer and use it in GitHub Desktop.
Creates a Windows library for local code repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create the folder | |
$folderPath = "$env:USERPROFILE\CodeRepositories" | |
New-Item -Path $folderPath -ItemType Directory | |
# create the Library Definition File | |
$libraryName = "CodeRepositories" | |
$libraryFilePath = "$env:APPDATA\Microsoft\Windows\Libraries\$libraryName.library-ms" | |
$libraryContent = @" | |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library"> | |
<name>@%SystemRoot%\system32\shell32.dll,-34597</name> | |
<version>6</version> | |
<isLibraryPinned>true</isLibraryPinned> | |
<iconReference>%SystemRoot%\system32\imageres.dll,-100</iconReference> | |
<templateInfo> | |
<folderType>GenericLibrary</folderType> | |
</templateInfo> | |
<defaultSaveFolder>$folderPath</defaultSaveFolder> | |
<searchConnectorDescriptionList> | |
<searchConnectorDescription> | |
<simpleLocation> | |
<url>$folderPath</url> | |
</simpleLocation> | |
</searchConnectorDescription> | |
</searchConnectorDescriptionList> | |
<knownFolderContentSourceList> | |
<knownFolderContentSource> | |
<guid>{5E6C858F-0E22-4760-9AFE-EA3317B67173}</guid> | |
</knownFolderContentSource> | |
</knownFolderContentSourceList> | |
</libraryDescription> | |
"@ | |
Set-Content -Path $libraryFilePath -Value $libraryContent | |
# pin the Library to Quick Access (Optional) | |
$libraryShell = New-Object -ComObject Shell.Application | |
$libraryFolder = $libraryShell.Namespace($libraryFilePath) | |
$quickAccessFolder = $libraryShell.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}") | |
$quickAccessFolder.Self.InvokeVerb("Pin to Quick access") | |
# create the sub directory | |
$libraryFolderPath = "$env:USERPROFILE\CodeRepositories" | |
$lanRepositoriesPath = Join-Path -Path $libraryFolderPath -ChildPath "LAN Repositories" | |
New-Item -Path $lanRepositoriesPath -ItemType Directory | |
# share the directory over the network | |
$shareName = "LANRepositories" | |
$description = "Shared LAN Repositories" | |
$folderToShare = $lanRepositoriesPath | |
New-SmbShare -Name $shareName -Path $folderToShare -Description $description -FullAccess Everyone | |
# set the NTFS permissions | |
$acl = Get-Acl -Path $folderToShare | |
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($accessRule) | |
Set-Acl -Path $folderToShare -AclObject $acl | |
# confirm the share | |
Get-SmbShare -Name $shareName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define paths | |
$libraryFolderPath = "$env:USERPROFILE\CodeRepositories" | |
$lanRepositoriesPath = Join-Path -Path $libraryFolderPath -ChildPath "LANRepositories" | |
$libraryName = "CodeRepositories" | |
$libraryFilePath = "$env:APPDATA\Microsoft\Windows\Libraries\$libraryName.library-ms" | |
$shareName = "LANRepositories" | |
# unshare the folder from the network | |
Remove-SmbShare -Name $shareName -Force | |
# remove the library | |
Remove-Item -Path $libraryFilePath -Force | |
# delete the directory | |
Remove-Item -Path $lanRepositoriesPath -Recurse -Force | |
# remove the "MyNewLibrary" library | |
Remove-Item -Path $libraryFilePath -Force | |
# remove the library folder if it's empty | |
if ((Get-ChildItem -Path $libraryFolderPath).Count -eq 0) { | |
Remove-Item -Path $libraryFolderPath -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment