Forum Discussion
Expand-DedupFile - expand files on other Servers?
It doesn't seem to work on UNC paths and mapped drives, I changed the script a little bit and used invoke-command to start the command locally on the remote server using the $folder_location to which PowerShell changes it's current directory and recursively deduplicates the files. It does work (Checked using the Measure-DedupFileMetadata cmdlet), but still throws errors like parameter incorrect 🙂
# Prompt user for file path
$folder_location = Read-Host -Prompt 'Enter the local path to the files to expand, e.g. e:\data'
# Prompt for server name
$server = Read-Host -Prompt 'Enter server name'
# Run remote command on remote server using foldername
Invoke-Command -ComputerName $server -ScriptBlock {
Push-Location $using:folder_location
Get-ChildItem -Recurse | Expand-DedupFile
}
- user4444Feb 02, 2022Copper ContributorHello,
apologies for the delayed response.
This script doesn't work, but I think it might be more to do with the paths to folders.
Perhaps if I explain the bigger picture it might help.
You were kind enough to help me with a script on another thread where I was searching for folders in various network locations. I suppose we could call that part 1 of the process.
After finding the folders I need to expand the files inside them.
I would like my colleague who uses these scripts to be able to run them from one location (not locally). To do that the paths to search will be network shares rather than local folders.
So, while the script to search for the folders in network shares works, it returns the locations as network paths, not local. The script you have provided here requires local paths. I did some testing using local paths but this didn't work, however, it's quite likely due to me making a mistake.- Feb 02, 2022
Strange, I tested it using invoke-command with a local path and it did return a error code but the Measure-DedupFileMetadata statistics showed me that the files were not dedupped anymore...
So, if you enter e:\data and servername server01.. It connects to server01 using a invoke-command and does a expand-dedupfile command on e:\data.Could take some time to dedup the files, but run a measure-dedupfilemetadata before and after running the script on the target server to check the diffence.
- user4444Feb 04, 2022Copper ContributorHello Harm_Veenstra,
I've performed some more testing and I think your script is working when using the Server name with the folder’s local path. I believe the cause of the failures are due to the users software having locked folder/files.
I received some inconsistent results which I now believe were due to the folder permissions being changed by the users first attempt to run their software. Their software deliberately locks the files, but doesn't unlock them when it fails to complete due to errors. The users software errors are due to the deduplicated files.
I need to wait on the user to provide fresh, untouched by their software, folder/files to confirm there is no problems on the Powershell side. I am quite confident this is the cause.
To troubleshoot the issue I manually expanded (expand-dedupfile) the files and checked the errors. I could see “access denied” errors. The user was able to revert the actions taken by their software. After doing so I was able to deduplicate the remaining files without the access denied errors.
I still have the problem of needing to know the local location of the folders. The script that searches for the folders runs remotely and searches network shares. Therefore, the paths returned are UNC paths, not the local path that the dedupe script requires.