递归生成md5文件列表,调用了外部的md5sums.exe和dos2unix.exe,是给Linux服务器md5批量文件校验用的。
工作中用的,没有修改,给大家做个参考吧。
#powershellscript Function colormsg($msg){ Write-Host -BackgroundColor Red -ForegroundColor yellow $msg } "###############Powershell MD5 Generator###############" colormsg("Second+ level directory not Supported") $dt = Get-Date $inc = [string]($dt) + " job started." colormsg($inc) "Environment Set" $local = (Resolve-Path .).Path $env = $env:path + ';' + $local $env:path = $env Set-Location ./ClientInstaller if(Test-Path *.MD5){ "MD5 file detected, will be removed, you have 5 seconds to cancel this action..." Start-Sleep 5 Remove-Item -Recurse *.md5 if($? -eq $True){"MD5 files removed!"} } "Processsing..." (Get-ChildItem -Recurse . | Resolve-Path -Relative) | ForEach-Object{$Fname = [string]($_.ToString().Split('\')[-1] + ".MD5") ; if( Test-Path -PathType Leaf $_){md5sums.exe -u -e $_.replace('\','/') | out-file -Encoding ascii $Fname ; if($? -eq $True){dos2unix.exe $Fname}else{Write-Error "MD5 file was not successfully generated!"} }} colormsg("Done!") Set-Location .. Start-Sleep 5
powershell的效率太低了,还是上C#吧,同样是调用外部命令,怎么差距就那么大尼!而且C#更高级的地方就是可以在linux下直接运行。