-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSet-LanmanServerSharesFilePath.ps1
64 lines (46 loc) · 2.16 KB
/
Set-LanmanServerSharesFilePath.ps1
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
Function Set-LanmanServerSharesFilePath {
<#
.Synopsis
Sets (or changes) the file path for Windows shares in the registry for the LanmanServerSharesFilePath reg key
.Description
Sets (or changes) the file path for Windows shares in the registry for the LanmanServerSharesFilePath reg key.
Use this function to update file paths in bulk for Windows shares.
.Example
Set-LanmanServerSharesFilePath -OldPath c:\ -NewPath d:\
Finds shares in Set-LanmanServerSharesFilePath reg key that match the old path and updates the value with the
new path
.Parameter OldFilePath
Existing file path in regkey named Set-LanmanServerSharesFilePath
.Parameter OldFilePath
New file path that will be updated in Set-LanmanServerSharesFilePath
.Notes
NAME: Set-LanmanServerSharesFilePath.ps1
AUTHOR: Mike Kanakos
VERSION: 1.0.0
DateCreated: 2019-07-31
DateUpdated: 2019-07-31
v 1.0.0 - initial function build
.Link
https://github.com/compwiz32/PowerShell
Originally found at https://martin77s.wordpress.com/2014/12/21/changing-shared-folders-path/
#>
[cmdletbinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $True, Position = 0)]
[String]$OldFilePath,
[Parameter(Mandatory = $True, Position = 1)]
[String]$NewFilePath
)
$RegPath = 'HKLM:SYSTEM\CurrentControlSet\Services\LanmanServer\Shares'
dir -Path $RegPath | Select-Object -ExpandProperty Property | ForEach-Object {
$ShareName = $_
$ShareData = Get-ItemProperty -Path $RegPath -Name $ShareName |
Select-Object -ExpandProperty $ShareName
if ($ShareData | Where-Object { $_ -eq "Path=$OldFilePath" }) {
$ShareData = $ShareData -replace [regex]::Escape("Path=$OldFilePath"), "Path=$NewFilePath"
if ($PSCmdlet.ShouldProcess($ShareName, 'Change-SharePath')) {
Set-ItemProperty -Path $RegPath -Name $ShareName -Value $ShareData
} #end if Set-ItemProperty
} #end If $sharedata
} #end ForEach
} #end Function