2016-01-08 54 views
0

当谈到PowerShell脚本时,我是一个完整的新手,但在编写Bat文件方面有合理的经验。Powershell/Bat文件合并

我有一个PowerShell脚本解压缩蝙蝠,reg文件和msi,powershell脚本然后启动bat文件,我不认为这是最好的方式来做到这一点,有没有办法只是得到powershell脚本解压缩,然后安装msi和reg文件,而不是运行一个单独的bat文件?

这里有2个文件:

BAT:

@echo off 

echo Installing Teamviewer, please wait... 
msiexec /qn /i "C:\Temp\TeamViewer.msi" /passive 
echo[ 
regedit /s C:\Temp\TeamViewer_Settings.reg 
Pause 
exit 

PS:

$BackUpPath = "C:\Temp\Install.zip" 

$Destination = "C:\Temp" 

Add-Type -assembly "system.io.compression.filesystem" 

[io.compression.zipfile]::ExtractToDirectory($BackUpPath, $destination) 

Start-Process "C:\Temp\installer.bat" 

有没有办法只运行PowerShell脚本并提取并安装所需要的文件?

非常感谢和善良,这是我的第一个PowerShell脚本。

回答

1

您使用start-process来运行bat文件,所以只需使用相同的方式运行msi文件。 由于没有powershell cmdlet导入regitry文件,因此您可以使用regedit.exe来导入reg文件。

Start-Process -FilePath 'msiexec.exe' -ArgumentList "/qn /i 'C:\Temp\TeamViewer.msi' /passive" -Wait 
Start-Process -Filepath 'regedit.exe' -ArgumentList "/s 'C:\Temp\TeamViewer_Settings.reg'" 
+0

嗨基兰,谢谢!这就说得通了!不知道为什么我不能一个人解决这个问题。 我现在收到此错误: 文件C:\ Temp \ tps.ps1无法加载。文件C:\ Temp \ tps.ps1未进行数字签名。你不能在当前系统上运行这个 脚本。有关运行脚本和设置执行策略的更多信息,请参阅 about_Execution_Policies,网址为http://go.microsoft.com/fwlink/?LinkID=135170。 + CategoryInfo:SecurityError:(:) [],ParentContainsErrorRecordException + FullyQualifiedErrorId:UnauthorizedAccess 如何签署脚本以便它运行? –

+0

欢迎标记....错误表明您的计算机上的执行策略设置为'allsigned',这意味着每个ps脚本在执行之前都需要进行签名....虽然这是最安全的选项,但大多数人将执行策略设置为'remotesigned' .. ...检查此链接以获取更多详细信息:https://technet.microsoft.com/en-us/library/ee176961.aspx?f = 255&MSPPError = -2147217396 ...注意:.launch powershell作为管理员 – Kiran

+0

也是这个链接如何签署脚本.....'https:// technet.microsoft.com/en-us/magazine/2008.04.powershell.aspx' – Kiran