零二年的夏天summer.blog.chinaunix.net
零二年的夏天
:)
全部博文(53)
2010年(4)
2009年(16)
2008年(33)
ljbzkl
unixorg
IT鹰
山定子
ghl123_c
大漠飞鸿
chenw_cu
jam20061
chinauni
格伯纳
_寒_CU
spider02
wqnear
zhwsh
ChpiTer
edaplaye
云幻无心
qinhanxi
分类: WINDOWS
2009-10-08 21:27:41
#===========================##Name:#Author:PopZslam#Description:#Version:##===========================param( [String]$LOCAL:sourceDirectory=$input, [String]$LOCAL:destinationDirectory=$(Get-Location))#===========================# Variables#===========================$LOCAL:notifyMessage=@( "请指定一个目录名。", "请指定目标目录名。", "您指定的参数不是目录:$LOCAL:sourceDirectory", "目标磁盘没有足够的剩余空间。", "您提供的参数不完整。")$LOCAL:destinationDirectorySize=0$LOCAL:sourceDirectorySize=0$LOCAL:newName=""$LOCAL:prefixString=""#===========================# Functions#===========================function get-freespace{ param([string]$LOCAL:destinationDirectory=(get-location)) if($LOCAL:destinationDirectory.Trim() -eq ""){ $LOCAL:destinationDirectory=(Get-Location); } $LOCAL:driveLeter=split-path -Path "$LOCAL:destinationDirectory" -qualifier $LOCAL:t=Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='$LOCAL:driveLeter'" foreach ($_ in $LOCAL:t){ return $_.freespace }}#===========================# Main Part#===========================# Check the parameter if((($LOCAL:sourceDirectory).trim() -eq "") ){ $LOCAL:notifyMessage[4] "command -source -destination" "command -source 'c:\source' -destination 'd:\destination'" exit}$LOCAL:destinationDirectorySize=get-freespace($LOCAL:destinationDirectory)if (Test-Path -Path $LOCAL:sourceDirectory -PathType Container){ $LOCAL:sourceDirectorySize=(Get-ChildItem -Force -Recurse -Path $LOCAL:sourceDirectory|Measure-Object -Property length -Sum).sum if ($LOCAL:sourceDirectorySize -ile $LOCAL:destinationDirectorySize){ foreach ($_ in (Get-ChildItem -Force -Recurse -Path $LOCAL:sourceDirectory) ){ if (Test-Path -Path $_.fullname -PathType Leaf){ $LOCAL:prefixString=Split-Path -Path $_.fullname -Parent |Split-Path -Leaf; $LOCAL:newName=$LOCAL:prefixString+"-"+$_.name Copy-Item -Path $_.fullname -Destination $LOCAL:destinationDirectory\$LOCAL:newName } } }else{ throw $LOCAL:notifyMessage[3] }}else{ throw $LOCAL:notifyMessage[2]}
上一篇:Windows Server 2003 Access-based Enumeration
下一篇:查看主板设备使用情况
登录 注册