【问题标题】:Powershell to install .\file errors, but when given full location C:\Users.... doesn't errorPowershell 安装 .\file 错误,但在给出完整位置 C:\Users.... 时不会出错
【发布时间】:2014-09-04 01:42:49
【问题描述】:

我在尝试访问文件时在该错误下方有一个脚本,但是如果我将 -argumentlist 中 .msi 文件的位置更改为完整地址,它会成功,但我不能让它像那样运行当我提交它以打包用于 SCCM 部署时,地址将发生变化。

    Function Get-OSCComputerOU
{
    $ComputerName = $env:computername
    $Filter = "(&(objectCategory=Computer)(Name=$ComputerName))"

    $DirectorySearcher = New-Object System.DirectoryServices.DirectorySearcher
    $DirectorySearcher.Filter = $Filter
    $SearcherPath = $DirectorySearcher.FindOne()
    $DistinguishedName = $SearcherPath.GetDirectoryEntry().DistinguishedName

    $OUName = ($DistinguishedName.Split(","))[1]
    $OUMainName = $OUName.SubString($OUName.IndexOf("=")+1)

    $OUMainName
}
$strOU = Get-OSCComputerOU
$strTrueOU=$strOU.split('_')[1]
$strCSV=Import-Csv \\SERVER\SHARE\FOLDER\CSV.csv
$strRoomChannel=$strCSV | where {$_.Room -eq $strTrueOU} | % channel
IF ($strRoomChannel){
$strRoomFoundArg="/i .\Installers\MSI.msi CHANNEL=$strRoomChannel"
Start-Process msiexec -ArgumentList $strRoomFoundArg -wait
} ELSE {
msg * "Channel is missing, and can not install correctly, please call tech support on Ext: to have this rectified, it's a quick fix."
}

当我使用如下所示的完整地址时,它可以正常安装.....这是怎么回事。

    Function Get-OSCComputerOU
{
    $ComputerName = $env:computername
    $Filter = "(&(objectCategory=Computer)(Name=$ComputerName))"

    $DirectorySearcher = New-Object System.DirectoryServices.DirectorySearcher
    $DirectorySearcher.Filter = $Filter
    $SearcherPath = $DirectorySearcher.FindOne()
    $DistinguishedName = $SearcherPath.GetDirectoryEntry().DistinguishedName

    $OUName = ($DistinguishedName.Split(","))[1]
    $OUMainName = $OUName.SubString($OUName.IndexOf("=")+1)

    $OUMainName
}
$strOU = Get-OSCComputerOU
$strTrueOU=$strOU.split('_')[1]
$strCSV=Import-Csv \\SERVER\SHARE\FOLDER\CSV.csv
$strRoomChannel=$strCSV | where {$_.Room -eq $strTrueOU} | % channel
IF ($strRoomChannel){
$strRoomFoundArg="/i C:\Users\USERNAME\Desktop\Installers\MSI.msi CHANNEL=$strRoomChannel"
Start-Process msiexec -ArgumentList $strRoomFoundArg -wait
} ELSE {
msg * "Channel is missing, and can not install correctly, please call tech support on Ext: to have this rectified, it's a quick fix."
}

我收到此错误:

【问题讨论】:

    标签: powershell installation windows-installer


    【解决方案1】:

    两者的区别在于'.'将由您正在调用的进程 msiexec 解决,与大多数进程一样,它将使用进程的 CurrentDirectory 来表示“.”,这与 PowerShell 中的当前位置不同。如果您在 PowerShell 中比较 Get-Location[Environment]::CurrentDirectory],您可以看到差异。如果您启动 powershell 并使用 Set-Location (aka cd) 更改目录,它们会有所不同。

    解决方案是在将路径发送到 msiexec 之前在 PowerShell 中解析路径:

    $path = Convert-Path .\Installers\MSI.msi
    $strRoomFoundArg = "/i `"$path`" CHANNEL=$strRoomChannel"
    Start-Process msiexec -ArgumentList $strRoomFoundArg -wait
    

    【讨论】:

      【解决方案2】:

      原来脚本对 MSI 文件前面的 .\ 不满意。

      如果我保留 .\,我会收到错误消息。

      如果我删除了 .\ 并且只有 MSI.msi,那么它工作正常。

      我没有提到我已将活动目录更改为我的桌面以执行脚本,我很抱歉@mike z

      非常感谢您的意见。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-02
        • 2019-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-08
        相关资源
        最近更新 更多