人生第一支Power Shell

一陣子沒發文了,最近說忙也不是很忙,時間都安排的恰恰好,到新公司服務也1個半月了,這段期間有很多獲得,也由於一直在 pick up 進度,實在也沒有什麼時間整理一些心得來更新我的網誌,今天是4天連假的第3天,為了不讓網誌過於荒涼就灌水一篇 - 我的第一支Power Shell。其實也沒什麼特別的,就只是想灌水。


以上聽起來很繞舌,但透過power shell ,很輕鬆就能達成任務。比起bat,更有彈性,也更能與.net 結合在一起。

# 檢查Flag
# 取得 Script 檔所在目錄
function Get-ScriptDirectory
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value
    Split-Path $Invocation.MyCommand.Path
$Flags = 2
$SleepSeconds = 2
$today = Get-Date -Format "yyyyMMdd"
$pt = (Join-Path (Get-ScriptDirectory) $today)

if (-not (Test-Path $pt))
    echo $pt
    New-Item -Path $pt -type directory

while ((Get-ChildItem $pt).Count -lt $Flags)
    echo "wait..."
    Start-Sleep -Seconds $SleepSeconds

$FlagName = "Flag_1" 
$today = Get-Date -Format "yyyyMMdd" 
$flags = 2 
$UNCPathArray = 

# echo $UNCPathArray.length 
for ($index = 0; $index -lt ($UNCPathArray.length) ; $index ++) 
  $UNCPath = $UNCPathArray[$index] + $today + "\" 
  # Flag_n 
  $path = $UNCPath + $FlagName 
  echo $UNCPath 
  if (-not (Test-Path $UNCPath)) 
    New-Item -Path $UNCPath -type directory 

  if (-not (Test-Path $path)) 
    New-Item -Path $path -type file 
    $path2 = $path + "_2" 
    New-Item -Path $path2 -type file 

  if ((Get-ChildItem $UNCPath).Count -eq $flags) 
    .(Join-Path ($UNCPathArray[$index]) "Go.bat") 

5 意見:


2014年6月17日 下午11:48

We won't even speak about red velvet cake, the sweet potato curry, and eggnog.
You ought to eat at least 3 portions of vegetables per day or even more.
Below are a few suggestions for a diabetes-free lifestyle.

My website - (


2014年6月18日 上午1:56

First of all, wireless home security cameras are cheap.
The password protect features may allow you to access the home
through key, pin, password, or card systems. Some are rather cheap, but
the very best will cost over a hundred dollars and sometimes more than a thousand dollars.

Take a look at my website :: cctv test monitor


2014年6月18日 上午2:00

It's difficult to find knowledgeable people in this particular topic, but you
seem like you know what you're talking about! Thanks

Here is my homepage - best weight loss pill


2014年6月18日 上午4:06

For the individuals who are technically audio, it may
be a routine procedure but for others it is a tiresome task.
It may consider you a while (It took me about 20 minutes to backup 4GB files).

Feel free to visit my website apptrackr zombieville usa


2014年6月19日 上午5:24

Yes! Finally something about psychotherapist.

Also visit my blog post - what is counseling psychology