Last active
August 12, 2022 16:13
-
-
Save eeveelution1313/e25984d7f7ef582357bc8899ca59d25a to your computer and use it in GitHub Desktop.
Drivepool Share MacOS Fix
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
$dppaths = @( | |
"C:\Mount\Disk00\PoolPart.58ccf061-34cd-4b90-8877-789471a4cbc0\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk01\PoolPart.1fbcfef0-2c61-4ab0-beb8-d0a1cadb768a\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk02\PoolPart.48abbdf0-37e1-4b38-89ca-f7bbbbd0615f\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk03\PoolPart.7e7212f5-f68e-4f39-b792-269b370f7d2a\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk04\PoolPart.6fdd8961-e5a2-41a6-8e26-a9193b61332a\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk05\PoolPart.af069264-5d06-4eb1-b5bd-378fbfbe95bf\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk06\PoolPart.ed255c38-3109-4acb-8d92-9e6feaa43f4d\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk07\PoolPart.5e61a41a-1d42-4519-b717-9fe8258fbdb1\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk08\PoolPart.b2baba49-9df8-4ddf-aa67-02450f73da29\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk09\PoolPart.bb8394cf-8bef-4548-ba28-0759fed0ec32\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk10\PoolPart.9f0eee81-9144-4868-ba17-ffd81d25c847\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\Disk11\PoolPart.1f3bc841-60bb-4c1c-b7cf-c5d3d7231c7b\PoolPart.a2be4e42-117f-4a0f-81f7-fe89c2e0acbf", | |
"C:\Mount\SSD1\PoolPart.241bc7bd-e692-4378-8775-04af35920a25\PoolPart.6ccd9907-2e6d-4f79-9b05-1976d0f2b066", | |
"C:\Mount\SSD2\PoolPart.b2603f43-c316-46f9-9e0f-3ca0da9915b7\PoolPart.6ccd9907-2e6d-4f79-9b05-1976d0f2b066" | |
) | |
# specify the path to the folder you want to monitor: | |
$Path = "A:\" | |
# specify which files you want to monitor | |
$FileFilter = '*' | |
# specify whether you want to monitor subfolders as well: | |
$IncludeSubfolders = $true | |
# specify the file or folder properties you want to monitor: | |
$AttributeFilter = [IO.NotifyFilters]::DirectoryName, [IO.NotifyFilters]::LastWrite | |
try | |
{ | |
$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{ | |
Path = $Path | |
Filter = $FileFilter | |
IncludeSubdirectories = $IncludeSubfolders | |
NotifyFilter = $AttributeFilter | |
} | |
# define the code that should execute when a change occurs: | |
$action = | |
{ | |
# the code is receiving this to work with: | |
# MY SHITTY CODE: | |
$details = $event.SourceEventArgs | |
$RealPath = $details.FullPath | |
if((get-item $details.FullPath) -is [System.IO.DirectoryInfo]){ | |
if($details.FullPath -notlike '*A:\*RECYCLE.BIN\*'){ | |
write-host "Real Path:" $RealPath | |
For ($i=0; $i -lt $dppaths.Length; $i++) { | |
#$dppaths[$i] | |
$dppath = $details.FullPath.replace('A:',$dppaths[$i]) | |
#write-host $dppath | |
if (Test-Path $dppath) { | |
write-host "DP Path - Current:" $dppath | |
}else{ | |
write-host "DP Path - New :" $dppath | |
New-Item $dppath -ItemType Directory | |
} | |
} | |
} | |
} | |
# MY SHITTY CODE OVER | |
} | |
# subscribe your event handler to all event types that are | |
# important to you. Do this as a scriptblock so all returned | |
# event handlers can be easily stored in $handlers: | |
$handlers = . { | |
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action | |
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action | |
} | |
# monitoring starts now: | |
$watcher.EnableRaisingEvents = $true | |
Write-Host "Watching for changes to $Path" | |
# since the FileSystemWatcher is no longer blocking PowerShell | |
# we need a way to pause PowerShell while being responsive to | |
# incoming events. Use an endless loop to keep PowerShell busy: | |
do | |
{ | |
# Wait-Event waits for a second and stays responsive to events | |
# Start-Sleep in contrast would NOT work and ignore incoming events | |
Wait-Event -Timeout 1 | |
# write a dot to indicate we are still monitoring: | |
#Write-Host "." -NoNewline | |
} while ($true) | |
} | |
finally | |
{ | |
# this gets executed when user presses CTRL+C: | |
# stop monitoring | |
$watcher.EnableRaisingEvents = $false | |
# remove the event handlers | |
$handlers | ForEach-Object { | |
Unregister-Event -SourceIdentifier $_.Name | |
} | |
# event handlers are technically implemented as a special kind | |
# of background job, so remove the jobs now: | |
$handlers | Remove-Job | |
# properly dispose the FileSystemWatcher: | |
$watcher.Dispose() | |
Write-Warning "Event Handler disabled, monitoring ends." | |
} | |
#Majority of the script is taken from here: https://powershell.one/tricks/filesystem/filesystemwatcher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment