Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过添加带有Orca的Powershell脚本来转换MSI_Powershell_Windows Installer_Orca - Fatal编程技术网

通过添加带有Orca的Powershell脚本来转换MSI

通过添加带有Orca的Powershell脚本来转换MSI,powershell,windows-installer,orca,Powershell,Windows Installer,Orca,我必须部署一个带有GPO的虚拟打印机软件。发布者提供的MSI安装程序工作正常,但在安装过程中没有将虚拟打印机设置为默认值的选项 所以我创建了这个“简单”的powershell脚本来更改默认打印机 ## Get the Printer with WMI $printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name = 'GreenPrint'" ## Set printer as default printer $

我必须部署一个带有GPO的虚拟打印机软件。发布者提供的MSI安装程序工作正常,但在安装过程中没有将虚拟打印机设置为默认值的选项

所以我创建了这个“简单”的powershell脚本来更改默认打印机

## Get the Printer with WMI
$printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name = 'GreenPrint'"

## Set printer as default printer
$printer.SetDefaultPrinter()
安装后手动执行此脚本工作正常,但 是否有办法通过使用转换文件(.mst)将此脚本包括在MSI的安装过程中

谢谢你的回答

使用Powershell完全安装

基于Niklas Sjögren的建议,我创建了一个Powershell脚本,安装MSI包,然后将打印机设置为默认。由于GPO没有提供登录时脚本只运行一次的选项,所以我使用注册表键检查是否需要处理

我认为您最好在工作站的初始配置中使用这种脚本,而不是使用logonscript

## Custom variables

$CompanyName = ‘YourCompany’
$InstallDir = "Path\Installer.msi"

## Set registry information for the local machine

$CompanyRegPath = "HKLM:\Software\"+$CompanyName

if (Test-Path $CompanyRegPath)
  {}
else
  {New-Item -path "HKLM:\Software\" -name $CompanyName}

if (Test-Path $CompanyRegPath'\Green Print')
  {}
else
  {New-Item -path $CompanyRegPath -name "Green Print"}

if ((Get-ItemProperty $CompanyRegPath'\Green Print').IsDeployed -eq $null)
  {Set-ItemProperty $CompanyRegPath'\Green Print' -name IsDeployed -Value 0}

#Retrieve registry information   
$IsDeployed = (Get-ItemProperty $CompanyRegPath'\Green Print').IsDeployed

if ($IsDeployed -ne 0)
  {}  
else
  {  
  ## Install the virtual printer software
  Start-Process $InstallDir /qn -Wait

  ## Get the Printer object with WMI
  $printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name = 'GreenPrint'"

  ## Set the Printer object as default printer
  $printer.SetDefaultPrinter()

  #Update the IsDeployed in registry
  Set-ItemProperty $CompanyRegPath’\Green Print’ -name IsDeployed -Value -1
  }

如何添加msi?可以简单地通过cmd文件运行msi,并将powershell.exe-file\*path*添加到一个新的行,然后使用组策略对象部署.msi(分配msi包)。使用带有“运行一次脚本”的GPO可能是一种解决方法,因为我认为我真的不需要使用原始策略更新/卸载此程序包。这是每个人的标准打印机吗?或者至少有几个用户?在这种情况下,我建议使用包含代码的登录脚本。我们公司也使用同样的方法,效果很好。(如果您使用2012或更高功能级别,请注意内置的登录脚本延迟5分钟)是的,打印机应该是标准的(查看以了解此虚拟打印机的用途)。但我不想在每次登录时都将其强制为“默认”,因为我相信有人会找到一个不使用它的好理由。这就是为什么脚本应该在安装过程中“运行一次/部分”。明天我将测试脚本安装而不是msi分配。如何添加msi?可以简单地通过cmd文件运行msi,并将powershell.exe-file\*path*添加到一个新的行,然后使用组策略对象部署.msi(分配msi包)。使用带有“运行一次脚本”的GPO可能是一种解决方法,因为我认为我真的不需要使用原始策略更新/卸载此程序包。这是每个人的标准打印机吗?或者至少有几个用户?在这种情况下,我建议使用包含代码的登录脚本。我们公司也使用同样的方法,效果很好。(如果您使用2012或更高功能级别,请注意内置的登录脚本延迟5分钟)是的,打印机应该是标准的(查看以了解此虚拟打印机的用途)。但我不想在每次登录时都将其强制为“默认”,因为我相信有人会找到一个不使用它的好理由。这就是为什么脚本应该在安装过程中“运行一次/部分”。明天我将测试脚本安装,而不是msi分配。