Well I've struggled long enough with this one. I have a project to compare two folders, one on each of two servers. We are comparing files on the source server with those on the target server and will create a list of the files from the source that will need to be refreshed once an update is completed on the target server.
Here's my script (many thanks to <a href="http://quickanddirtyscripting.wordpress.com" rel="nofollow">http://quickanddirtyscripting.wordpress.com</a> for the original) :
Now for some reason if I run this against local paths say
it works fine, but when I run it using
paths between two servers I get
<blockquote>
<strong>Exception calling "OpenRead" with "1" argument(s): "The given path's format is not supported."</strong>
</blockquote>
Any help with this would be greatly appreciated. The end result should be a list of files, but for some reason it doesn't like the
path.
The script name is
and is called as such:
<-- This works
<-- Returns the aforementioned exception.
Why?
Here's my script (many thanks to <a href="http://quickanddirtyscripting.wordpress.com" rel="nofollow">http://quickanddirtyscripting.wordpress.com</a> for the original) :
Code:
param ([string] $src,[string] $dst)
function get-DirHash()
{
begin
{
$ErrorActionPreference = "silentlycontinue"
}
process
{
dir -Recurse $_ | where { $_.PsIsContainer -eq $false -and ($_.Name -like "*.js" -or $_.Name -like "*.css"} | select Name,FullName,@{Name="SHA1 Hash"; Expression={get-hash $_.FullName -algorithm "sha1" }}
}
end
{
}
}
function get-hash
{
param([string] $file = $(throw 'a filename is required'),[string] $algorithm = 'sha256')
try
{
$fileStream = [system.io.file]::openread((resolve-path $file));
$hasher = [System.Security.Cryptography.HashAlgorithm]::create($algorithm);
$hash = $hasher.ComputeHash($fileStream);
$fileStream.Close();
}
catch
{
write-host $_
}
return $hash
}
Compare-Object $($src | get-DirHash) $($dst | get-DirHash) -property @("Name", "SHA1 Hash")
Now for some reason if I run this against local paths say
Code:
c:\temp\test1 c:\temp\test2
Code:
UNC
<blockquote>
<strong>Exception calling "OpenRead" with "1" argument(s): "The given path's format is not supported."</strong>
</blockquote>
Any help with this would be greatly appreciated. The end result should be a list of files, but for some reason it doesn't like the
Code:
UNC
The script name is
Code:
compare_js_css.ps1
Code:
.\compare_js_css.ps1 c:\temp\test1 c:\temp\test2
Code:
.\compare_js_css.ps1 \\\\devserver1\c$\websites\site1\website \\\\devserver2\c$\websites\site1\website
Why?