簡體   English   中英

Powershell-在目錄中的所有ps1文件上運行ps1腳本

[英]Powershell - running a ps1 script on all ps1 files in a directory

我在本地服務器目錄上有大約50個ps1腳本-E:/ scripts /。 它們具有收集服務器/應用程序統計信息等的不同功能。

已更新,以添加有關腳本的更多信息。還有第二個ps1腳本-a.ps1,我正嘗試使用powershell運行它。 這a.ps1有一個函數定義- FN運行-並做了之后Import-Module a.ps1 ,它使用的語法如下:

fn-run <stats collector script name> servername domainname
for example:
fn-run E:/scripts/script1.ps1 myserver localdomain

我可以使用powershell收集腳本文件列表,如下所示:

$i = 0    
$allscripts = Get-ChildItem E:/scripts/ | where {$_.extension -eq ".ps1"} | % {
         Write-Host $_.FullName
    }

foreach ($script in $allscripts) {
    $script,
    $i++
    }

這給出了E:/ scripts /目錄中腳本文件的完整列表。 現在,我試圖找出如何將它們傳遞給a.ps1 ..?

謝謝..

這是您要做什么?

Import-Module a.ps1

$allscripts = Get-ChildItem -Path  E:/scripts/ -Filter "*.ps1" | Select-Object -ExpandProperty FullName

foreach ($script in $allscripts) {
    fn-run $script myserver localdomain
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM