【发布时间】:2018-12-21 13:27:15
【问题描述】:
我有一个批处理脚本,但我想为 PowerShell 制作同样的脚本
这是我的批处理脚本循环:
for /F "tokens=1" %%z in ('%MYSQL% -U postgres -l ^| findstr "beheer forms loket kcs mo alfresco"') do (
echo Dumping database %%z
%MYPGDUMP% -h localhost -p 5432 -U postgres -F c -b -f "% %%%z".backup %%z
)
)
现在我需要同样的,但对于 PowerShell。到目前为止,我有这个:
$database=Set-Location 'E:\Exxellence\PostgreSQL\9.5\bin\';
.\psql --% -U postgres -l | Out-String -Stream | Select-String -Pattern "beheer"
foreach ($database in $database) {
Set-Location 'E:\Exxellence\PostgreSQL\9.5\bin\';
.\pg_dump --% -h localhost -p 5432 -U postgres -F c -b -f "$database.backup"
}
【问题讨论】:
-
也许从发布您到现在为止使用 powershell 尝试过的内容开始?
-
有这样的东西。 $database=Set-Location 'E:\Exxellence\PostgreSQL\9.5\bin\'; .\psql --% -U postgres -l |串外流 | Select-String -Pattern "beheer" ForEach ($database in $database) { Set-Location 'E:\Exxellence\PostgreSQL\9.5\bin\'; .\pg_dump --% -h localhost -p 5432 -U postgres -F c -b -f "$database.backup" }
-
请编辑您的问题并在此处插入代码。
标签: powershell loops batch-file for-loop scripting