2014-11-05 38 views
0

我有一個腳本,應該創建一些文件夾,如果他們不存在。Powershell選擇一個屬性作爲原始類型

"a","b","c" ` 
    | select @{Name="path"; Expression={Join-Path "C:\temp" $_}} ` 
    | select -ExpandProperty path ` 
    | where { -Not (Test-Path $_)} 

是否可以提取聯接路徑字符串更優雅,在新的對象將其分配給指定的屬性path,然後用另一種選擇與-ExpandProperty?

回答

2

爲什麼不乾脆:

"a","b","c" | %{ 
    Join-Path "C:\temp" $_ } | where { -not (Test-Path $_)} 
+0

我要查找什麼呢%{}做 – Axarydax 2014-11-05 09:19:04

+1

對不起,我已經開發了一下。 %是Foreach對象的別名。所以基本上對於數組中的每個元素(「a」,「b」,「c」),我們執行連接路徑並對其進行測試。 – 2014-11-05 09:28:31