Last active
March 26, 2024 03:12
-
-
Save DavideDunne/f042cd37e5abde1f03bea9929a7b446e to your computer and use it in GitHub Desktop.
Get all the folders that are being shared by the SMB on the current machine and make a shortcut for each of all of those inside a given folder
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
param( | |
# Folder path where the shortcuts will be created | |
[Parameter(Mandatory=$true)] | |
[string]$Folder | |
) | |
# Test if folder is a valid path of a folder | |
if (-not (Test-Path $Folder -PathType Container)) { | |
Write-Host "Folder path is not valid" | |
exit | |
} | |
# Get all shared folders | |
# Exclude Remote IPC and the C:\ root folder and the folder where the shortcuts will be created | |
$SharedFoldersList = Get-SmbShare | Where-Object { $_.Name -ne 'IPC$' } | |
| Where-Object { $_.Name -ne $Folder } | |
| Where-Object { $_.Name -ne 'C$' } | |
| Select-Object -Property Path | |
foreach($SharedFolder in $SharedFoldersList.Path) { | |
# Create a shortcut for each shared folder | |
Write-Host "Creating shortcut for $SharedFolder" | |
$WshShell = New-Object -ComObject WScript.Shell | |
$FolderName = Split-Path -Path $SharedFolder -Leaf | |
$Shortcut = $WshShell.CreateShortcut("$Folder\$FolderName.lnk") | |
$Shortcut.TargetPath = $SharedFolder | |
$Shortcut.Save() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment