小编Bob*_*man的帖子

Powershell UNC Path不支持异常

好吧,我在这个问题上已经挣扎了很长时间.我有一个项目来比较两个文件夹,两个服务器各一个.我们将源服务器上的文件与目标服务器上的文件进行比较,并在目标服务器上完成更新后创建源文件列表,这些文件需要刷新.

这是我的脚本(非常感谢原文http://quickanddirtyscripting.wordpress.com):

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
    { …
Run Code Online (Sandbox Code Playgroud)

powershell unc filepath

3
推荐指数
1
解决办法
4441
查看次数

标签 统计

filepath ×1

powershell ×1

unc ×1