将批处理脚本转换为powershell 我是PopeBeSH的新手,我们正处于迁移应用程序的中间,需要将一个旧的遗留批处理脚本转换成PosiS壳。批处理脚本使用了很多旧的传统工具,如RCMD、XCopy,并很快地执行该要求。有人能帮我把这个脚本转换成powershell吗..如果能解释这些步骤,我将非常感激

将批处理脚本转换为powershell 我是PopeBeSH的新手,我们正处于迁移应用程序的中间,需要将一个旧的遗留批处理脚本转换成PosiS壳。批处理脚本使用了很多旧的传统工具,如RCMD、XCopy,并很快地执行该要求。有人能帮我把这个脚本转换成powershell吗..如果能解释这些步骤,我将非常感激,powershell,batch-file,Powershell,Batch File,提前谢谢 SET server=\\XAEO002.NET. SET importShare=\\cefl03.net.\ioponguard :BEGIN IF NOT EXIST %importshare%\prod\data\in\Nordics\FI01_Debtor.csv GOTO END IF NOT EXIST %importshare%\prod\data\in\Nordics\FI01_OpenItems.csv GOTO END IF NOT EXIST %imports

提前谢谢

SET server=\\XAEO002.NET.
SET importShare=\\cefl03.net.\ioponguard

:BEGIN
IF NOT EXIST %importshare%\prod\data\in\Nordics\FI01_Debtor.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\FI01_OpenItems.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\SE01_Debtor.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\SE01_OpenItems.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\NO01_Debtor.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\NO01_OpenItems.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\DK01_Debtor.csv GOTO END
IF NOT EXIST %importshare%\prod\data\in\Nordics\DK01_OpenItems.csv GOTO END

RCMD %Server% XCOPY D:\Data\Onguard\Bestanden\Nordics\*.* D:\Data\Onguard\Bestanden\Nordics\History /c /h /r /y
ATTRIB -r %Server%\D$\Data\Onguard\Bestanden\Nordics\*.*
RCMD %Server% DEL /F D:\data\onguard\bestanden\Nordics\*Debtor.csv
RCMD %Server% DEL /F D:\data\onguard\bestanden\Nordics\*OpenItems.csv

::  Copy data files to target folder on OnGuard server and remove from source IOP folder

XCOPY /C /H /R /Y %importshare%\prod\data\in\Nordics\*Debtor.csv  %Server%\D$\Data\Onguard\Bestanden\Nordics\
XCOPY /C /H /R /Y %importshare%\prod\data\in\Nordics\*OpenItems.csv %Server%\D$\Data\Onguard\Bestanden\Nordics\
ECHO Y|DEL %importshare%\prod\data\in\Nordics\*Debtor.*
ECHO Y|DEL %importshare%\prod\data\in\Nordics\*OpenItems.*

::  Save previous intermediate data files and logfiles into history subfolders

RCMD %Server% XCOPY /C /H /R /Y D:\Data\Onguard\Debite~1\Nordics\*.* D:\Data\Onguard\Debite~1\Nordics\History
ECHO Y|DEL %server%\D$\data\onguard\Debite~1\Nordics\*.*
RCMD %Server% XCOPY /C /H /R /Y D:\Data\Onguard\Factuu~1\Nordics\*.* D:\Data\Onguard\Factuu~1\Nordics\History
ECHO Y|DEL %server%\D$\data\onguard\Factuu~1\Nordics\*.*
RCMD %Server% XCOPY /C /H /R /Y D:\Data\Onguard\Import\log\Nordics\*.*   D:\Data\Onguard\Import\log\Nordics\History
ECHO Y|DEL %server%\D$\data\onguard\import\log\Nordics\*.*

:: Start remotely the OnGuard PreProcessor and succesively OnGuard commandImport process

soon %server% 60 /INTERACTIVE D:\apps\OnGuard\Preprocessor.exe -a=NL  server=pdb11v.net\inst1 db=OnGuard trusted=yes

soon %server% 500 /INTERACTIVE D:\apps\OnGuard\CmdImport.exe server=pdb11v.net\inst1 db=OnGuard trusted=yes admin=6,7,8,9

:END

SET Server=
SET ImportShare=

这里发生了很多不同的事情。首先,您需要处理变量,因此:

$server="\\XAEO002.NET."
$importShare="\\cefl03.net.\ioponguard"
然后循环遍历路径,如果路径不存在,则返回

$path = "$importshare\prod\data\in\Nordics\"

#Creates a list of Paths that we can check, or exit out of script if they don't exist
$paths = foreach($file in @("FI01_Debtor.csv", "FI01_OpenItems.csv", "SE01_Debtor.csv", "SE01_OpenItems.csv", "NO01_Debtor.csv", "NO01_OpenItems.csv", "DK01_Debtor.csv", "DK01_OpenItems.csv"))
{
  "$path$file"
}

foreach ($fullpath in $paths)
{
  If (-not (Test-Path $fullpath -ErrorAction "SilentlyContinue") ) { return }
}
接下来,为了替换您的RCMD调用,您可以使用Invoke命令,对于XCOPY/C/H/R/Y,您可以使用robocy/e:、和/A-:R来执行ATTRIB-R。或者,您可以保持XCOPY和ATTRIB的执行,因为PowerShell将乐于使用它们

Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe D:\Data\Onguard\Bestanden\Nordics\ D:\Data\Onguard\Bestanden\Nordics\History /S /A-:R /R:0}
替换ECHO Y | DEL%importshare%\prod\data\in\Nordics*Debter.*可以非常简单

Remove-Item "$importShare\prod\data\in\Nordics\*Debtor.*" -Force
继续我们之前的工作,但是为了在最后很快执行,您可以将该批次作为远程命令块的一部分执行:

Invoke-Command -ComputerName $server -ScriptBlock {
  D:\apps\OnGuard\Preprocessor.exe -a=NL  server=pdb11v.net\inst1 db=OnGuard trusted=yes
  <#
    If you need to wait in between commands, you could throw in a:
    Sleep -Seconds 3600
  #>
  D:\apps\OnGuard\CmdImport.exe server=pdb11v.net\inst1 db=OnGuard trusted=yes admin=6,7,8,9
}
为了在远程服务器上运行此命令,需要在调用命令期间执行上述命令

或者,SCHTASKS仍然可用,您可以在命令中为其指定服务器:

SCHTASKS /S $server /Create /SC DAILY /TN PreProcessor /TR 'D:\apps\OnGuard\Preprocessor.exe' /ST 09:00
您可以通过以下方式获得更多选项:

SCHTASKS /Create /? 
我希望这有帮助


谢谢你,克里斯。

克里斯,真是太棒了。。这一定会指引我走向成功。。你真是太棒了。。!!!以上代码中还有一个帮助。。。很快%server%60/INTERACTIVE D:\apps\OnGuard\Preprocessor.exe-a=NL server=pdb11v.net\inst1 db=OnGuard trusted=yes很快%server%500/INTERACTIVE D:\apps\OnGuard\CmdImport.exe server=pdb11v.net\inst1 db=OnGuard trusted=yes admin=6,7,8,9这些代码实际上正在任务计划程序中创建计划作业。。如何使用powershell进行模拟…您可以使用Schtasks.exe进行模拟,也可以在powershell(v3.0及更高版本)中使用以下cmdlet进行模拟:New ScheduledTaskAction、New ScheduledTaskRigger、New ScheduledTask和Register ScheduledTask$action=New scheduledtaskaaction-Execute'D:\apps\OnGuard\Preprocessor.exe'-Argument'-a=NL server=pdb11v.net\inst1 db=OnGuard trusted=yes'$trigger=New ScheduledTaskTrigger-Daily-At上午9点注册ScheduledTask-action$action-trigger-TaskName“AppLog”-描述“AppLog的每日转储”我在原始答案中添加了Schtasks.exe和Register ScheduleTask样式的命令。
#  Chris made this possible...Full marks to him.. :)

$ErrorActionPreference = "Continue"
$Dte =(get-date).tostring("dd-MM-yyyy")
Start-Transcript -path "C:\temp\EYGSA-$Dte.txt" -append


Function Start-Countdown 
{   
Param(
    [Int32]$Seconds = 1500,
    [string]$Message = "Pausing Script for 1500 seconds..."
)
ForEach ($Count in (1..$Seconds))
{   Write-Progress -Id 1 -Activity $Message -Status "Script will resume    after $Seconds seconds, $($Seconds - $Count) Seconds left" -PercentComplete (($Count / $Seconds) * 100)
    Start-Sleep -Seconds 1
}
Write-Progress -Id 1 -Activity $Message -Status "Resuming" -PercentComplete 100 -Completed
}


$server="\\XAEO002.NET"
$importShare="\\cefl03.net.\ioponguard"


cls
write-host "`n"(" "*67)"`n"(" "*20)"00 / 16 TASK COMPLETED..."(" "*20)"`n"("   "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Varifying the .CSV Files are valid ...`n" -foreground "Yellow"

$path = "$importshare\prod\data\in\"

$paths = foreach($file in @("ATL01_Debitor.csv", "ATL01_OpenItems.csv",    "ATL02_Debitor.csv", "ATL02_OpenItems.csv", "ATL03_Debitor.csv", "ATL03_OpenItems.csv", "ATL04_Debitor.csv", "ATL04_OpenItems.csv", "ATL05_Debitor.csv", "ATL05_OpenItems.csv", "ATL06_Debitor.csv", "ATL06_OpenItems.csv", "CHL01_Debitor.csv", "CHL01_OpenItems.csv", "CHL02_Debitor.csv", "CHL02_OpenItems.csv", "DEL10_Debitor.csv", "DEL10_OpenItems.csv", "DEL22_Debitor.csv", "DEL22_OpenItems.csv", "DEL44_Debitor.csv", "DEL44_OpenItems.csv", "DEL48_Debitor.csv", "DEL48_OpenItems.csv"))
{
"$path$file"
}

foreach ($fullpath in $paths)
{
write-host "Varifying File : $fullpath"
If (-not (Test-Path $fullpath -ErrorAction "SilentlyContinue") ) 
{ 
write-host "`nFile varification $fullpath Failed.!! `a`n`nAbandoning the   script`n " -foreground "magenta"
Stop-Transcript
return 
}
}

cls
write-host "`n"(" "*67)"`n"(" "*20)"01 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Bestanden\GSA\ to History ...`n" -foreground "yellow"

 Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe D:\Data\Onguard\Bestanden\GSA\ D:\Data\Onguard\Bestanden\GSA\History /A-:R /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"02 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing Bestanden\GSA ... `n" -foreground "yellow"


Remove-Item "\\$server\D$\data\onguard\bestanden\GSA\*Debitor.csv" -Force
Remove-Item "\\$server\D$\data\onguard\bestanden\GSA\*OpenItems.csv" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"03 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \data\in\ to \Bestanden\GSA\ ...`n" -foreground "yellow"

 Robocopy.exe $importshare\prod\data\in\ \\$Server\D$\Data\Onguard\Bestanden\GSA\ *Debtor.csv /R:0
 Robocopy.exe $importshare\prod\data\in\ \\$Server\D$\Data\Onguard\Bestanden\GSA\ *OpenItems.csv /R:0

 cls
write-host "`n"(" "*67)"`n"(" "*20)"04 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing Debtor, OpenItems ...`n" -foreground "yellow"

Remove-Item "$importShare\prod\data\in\*Debitor.*" -Force
Remove-Item "$importshare\prod\data\in\*OpenItems.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"05 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Debiteur XML\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\OnGuard\Debiteur XML\GSA\/" "D:\Data\OnGuard\Debiteur XML\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"06 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \Debiteur XML\GSA ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\Debiteur XML\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"07 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Factuur XML\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\OnGuard\Factuur XML\GSA\/" "D:\Data\OnGuard\Factuur XML\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"08 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \Factuur XML\GSA ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\Factuur XML\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"09 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \log\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\Onguard\Import\log\GSA\/" "D:\Data\Onguard\Import\log\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"10 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \log\Nordics ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\import\log\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"11 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Creating Schedule Task for Preprocessor.exe ...`n" -foreground "yellow"

Invoke-Command -ComputerName $server -ScriptBlock { SCHTASKS.EXE /create /tn (get-date).tostring("P-dd-MM-yyyy,HH.mm.ss") /sc once /st (get-date).Addminutes(1).ToString("HH:mm") /tr "D:\apps\OnGuard\Preprocessor.exe -a=NL server=pdb11v.net.net\inst1 db=OnGuard trusted=no"}

cls
write-host "`n"(" "*67)"`n"(" "*20)"12 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Creating Schedule Task for CmdImport.exe ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { SCHTASKS.EXE /create /tn (get-date).tostring("C-dd-MM-yyyy,HH.mm.ss") /sc once /st (get-date).Addminutes(9).ToString("HH:mm") /tr "D:\apps\OnGuard\CmdImport.exe server=pdb11v.net\inst1 db=OnGuard trusted=no admin=5"}

cls
write-host "`n`n`n`n"(" "*67)"`n"(" "*20)"13 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
#write-host "Please wait the script will resume after 25 minuts .. `n" -   foreground "yellow" -backgroundcolor "Red"
#Sleep -Seconds 1500


Start-Countdown -Seconds 1500 -Message "Do not close or cancel this window.."

cls
write-host "`n"(" "*67)"`n"(" "*20)"14 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying File Impaddressen.log ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "C:\windows\system32\/" "D:\Data\Onguard\Import\log\" Impaddressen.log /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"15 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "RemovingFile Impaddressen.log from System32 ...`n" -foreground "yellow"
Remove-Item "\\$server\C$\windows\system32\ImpAddressen.log" -Force -ErrorAction SilentlyContinue

cls
write-host "`n"(" "*67)"`n"(" "*20)"16 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Script Completed.."




Stop-Transcript
#  Chris made this possible...Full marks to him.. :)

$ErrorActionPreference = "Continue"
$Dte =(get-date).tostring("dd-MM-yyyy")
Start-Transcript -path "C:\temp\EYGSA-$Dte.txt" -append


Function Start-Countdown 
{   
Param(
    [Int32]$Seconds = 1500,
    [string]$Message = "Pausing Script for 1500 seconds..."
)
ForEach ($Count in (1..$Seconds))
{   Write-Progress -Id 1 -Activity $Message -Status "Script will resume    after $Seconds seconds, $($Seconds - $Count) Seconds left" -PercentComplete (($Count / $Seconds) * 100)
    Start-Sleep -Seconds 1
}
Write-Progress -Id 1 -Activity $Message -Status "Resuming" -PercentComplete 100 -Completed
}


$server="\\XAEO002.NET"
$importShare="\\cefl03.net.\ioponguard"


cls
write-host "`n"(" "*67)"`n"(" "*20)"00 / 16 TASK COMPLETED..."(" "*20)"`n"("   "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Varifying the .CSV Files are valid ...`n" -foreground "Yellow"

$path = "$importshare\prod\data\in\"

$paths = foreach($file in @("ATL01_Debitor.csv", "ATL01_OpenItems.csv",    "ATL02_Debitor.csv", "ATL02_OpenItems.csv", "ATL03_Debitor.csv", "ATL03_OpenItems.csv", "ATL04_Debitor.csv", "ATL04_OpenItems.csv", "ATL05_Debitor.csv", "ATL05_OpenItems.csv", "ATL06_Debitor.csv", "ATL06_OpenItems.csv", "CHL01_Debitor.csv", "CHL01_OpenItems.csv", "CHL02_Debitor.csv", "CHL02_OpenItems.csv", "DEL10_Debitor.csv", "DEL10_OpenItems.csv", "DEL22_Debitor.csv", "DEL22_OpenItems.csv", "DEL44_Debitor.csv", "DEL44_OpenItems.csv", "DEL48_Debitor.csv", "DEL48_OpenItems.csv"))
{
"$path$file"
}

foreach ($fullpath in $paths)
{
write-host "Varifying File : $fullpath"
If (-not (Test-Path $fullpath -ErrorAction "SilentlyContinue") ) 
{ 
write-host "`nFile varification $fullpath Failed.!! `a`n`nAbandoning the   script`n " -foreground "magenta"
Stop-Transcript
return 
}
}

cls
write-host "`n"(" "*67)"`n"(" "*20)"01 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Bestanden\GSA\ to History ...`n" -foreground "yellow"

 Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe D:\Data\Onguard\Bestanden\GSA\ D:\Data\Onguard\Bestanden\GSA\History /A-:R /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"02 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing Bestanden\GSA ... `n" -foreground "yellow"


Remove-Item "\\$server\D$\data\onguard\bestanden\GSA\*Debitor.csv" -Force
Remove-Item "\\$server\D$\data\onguard\bestanden\GSA\*OpenItems.csv" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"03 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \data\in\ to \Bestanden\GSA\ ...`n" -foreground "yellow"

 Robocopy.exe $importshare\prod\data\in\ \\$Server\D$\Data\Onguard\Bestanden\GSA\ *Debtor.csv /R:0
 Robocopy.exe $importshare\prod\data\in\ \\$Server\D$\Data\Onguard\Bestanden\GSA\ *OpenItems.csv /R:0

 cls
write-host "`n"(" "*67)"`n"(" "*20)"04 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing Debtor, OpenItems ...`n" -foreground "yellow"

Remove-Item "$importShare\prod\data\in\*Debitor.*" -Force
Remove-Item "$importshare\prod\data\in\*OpenItems.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"05 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Debiteur XML\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\OnGuard\Debiteur XML\GSA\/" "D:\Data\OnGuard\Debiteur XML\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"06 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \Debiteur XML\GSA ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\Debiteur XML\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"07 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \Factuur XML\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\OnGuard\Factuur XML\GSA\/" "D:\Data\OnGuard\Factuur XML\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"08 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \Factuur XML\GSA ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\Factuur XML\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"09 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying \log\GSA to History ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "D:\Data\Onguard\Import\log\GSA\/" "D:\Data\Onguard\Import\log\GSA\History" /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"10 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Removing \log\Nordics ...`n" -foreground "yellow"
Remove-Item "\\$server\D$\data\onguard\import\log\GSA\*.*" -Force

cls
write-host "`n"(" "*67)"`n"(" "*20)"11 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Creating Schedule Task for Preprocessor.exe ...`n" -foreground "yellow"

Invoke-Command -ComputerName $server -ScriptBlock { SCHTASKS.EXE /create /tn (get-date).tostring("P-dd-MM-yyyy,HH.mm.ss") /sc once /st (get-date).Addminutes(1).ToString("HH:mm") /tr "D:\apps\OnGuard\Preprocessor.exe -a=NL server=pdb11v.net.net\inst1 db=OnGuard trusted=no"}

cls
write-host "`n"(" "*67)"`n"(" "*20)"12 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Creating Schedule Task for CmdImport.exe ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { SCHTASKS.EXE /create /tn (get-date).tostring("C-dd-MM-yyyy,HH.mm.ss") /sc once /st (get-date).Addminutes(9).ToString("HH:mm") /tr "D:\apps\OnGuard\CmdImport.exe server=pdb11v.net\inst1 db=OnGuard trusted=no admin=5"}

cls
write-host "`n`n`n`n"(" "*67)"`n"(" "*20)"13 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
#write-host "Please wait the script will resume after 25 minuts .. `n" -   foreground "yellow" -backgroundcolor "Red"
#Sleep -Seconds 1500


Start-Countdown -Seconds 1500 -Message "Do not close or cancel this window.."

cls
write-host "`n"(" "*67)"`n"(" "*20)"14 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Copying File Impaddressen.log ...`n" -foreground "yellow"
Invoke-Command -ComputerName $server -ScriptBlock { Robocopy.exe "C:\windows\system32\/" "D:\Data\Onguard\Import\log\" Impaddressen.log /R:0}

cls
write-host "`n"(" "*67)"`n"(" "*20)"15 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "RemovingFile Impaddressen.log from System32 ...`n" -foreground "yellow"
Remove-Item "\\$server\C$\windows\system32\ImpAddressen.log" -Force -ErrorAction SilentlyContinue

cls
write-host "`n"(" "*67)"`n"(" "*20)"16 / 16 TASK COMPLETED..."(" "*20)"`n"(" "*67)"`n`n" -backgroundcolor "White" -foreground "Red"
write-host "Script Completed.."




Stop-Transcript