我在foreach部分stucked。我找不到任何解決方案在一個foreach循環中生成2個不同的列表。我使用了2 foreach但它並沒有幫助。分享了我的願望輸出。生成2個不同的列表在一個foreach循環與powershell
我的代碼:
$InStuff = @'
a
b
c
'@.Split("`n").Trim()
$InStuff2 = @'
1
2
3
'@.Split("`n").Trim()
$SPart_1 = 'application="'
$SPart_2 = ' path='
$SPart_3 = ' name='
$SPart_4 = ' application'
foreach ($IS_Item in $InStuff) {
foreach ($IS2_Item in $InStuff2) {
$UName = $IS_Item
$UName2 = $IS2_Item
$Sentence = -join (
$SPart_1, $UName,
$SPart_2, $UName2,
$SPart_3, $UName2,
$SPart_4
)
''
$Sentence
}
}
故障輸出:
application="a path=1 name=1 application
application="a path=2 name=2 application
application="a path=3 name=3 application
application="b path=1 name=1 application
application="b path=2 name=2 application
application="b path=3 name=3 application
application="c path=1 name=1 application
application="c path=2 name=2 application
application="c path=3 name=3 application
我的願望輸出:
application="a path=1 name=1 application
application="b path=2 name=2 application
application="c path=3 name=3 application
謝謝
ty brendan;)欣賞它 –