从PowerShell脚本运行批处理文件

时间:2019-04-03 20:00:51

标签: powershell batch-file

我无法从PowerShell脚本运行.bat文件。我认为这与powershell变量和bat文件的运行有关,但是我不确定。请帮忙。

代码如下:

$pc = Get-ChildItem Env:Computername
$pc = $pc.Value

$profiles = gci \\$pc\c$\users -Exclude Public,*Remote*,*Backup*, *SQL*, *Iris*,*.DMI_NT, *admin* |
            Sort-Object LastWriteTime -Descending |
            %{$_.Name}

Write-Host "the computer name is $pc and the username is $profiles"
foreach ($user in $profiles) {
    Write-Host "restoring data on $pc for $user" 
    if (Test-Path "\\dmi4\home\$user\$pc") {
        Start-Process "\\dmi4\home\$user\$pc\restore-favorites.bat" -Wait
        Start-Process "\\dmi4\home\$user\$pc\restore-printers.bat" -Wait
        Start-Process "\\dmi4\home\$user\$pc\restore-shortcuts.bat" -Wait
        Start-Process "\\dmi4\home\$user\$pc\restore-signatures.bat" -Wait
        Start-Process "\\dmi4\home\$user\$pc\restore-chromebookmarks.bat" -Wait
     } elseif (Test-Path "\\dmi9\home\$user\$pc") {      
        Start-Process "\\dmi9\home\$user\$pc\restore-favorites.bat" -Wait -WindowStyle Hidden
        Start-Process "\\dmi9\home\$user\$pc\restore-printers.bat" -Wait -WindowStyle Hidden
        Start-Process "\\dmi9\home\$user\$pc\restore-shortcuts.bat" -Wait -WindowStyle Hidden
        Start-Process "\\dmi9\home\$user\$pc\restore-signatures.bat" -Wait -WindowStyle Hidden
        Start-Process "\\dmi9\home\$user\$pc\restore-chromebookmarks.bat" -Wait -WindowStyle Hidden
     }
}

0 个答案:

没有答案