0

I'm having some issues with trying to install various programs via powershell. This is an example (trimmed down) of the component of the module I've built:

Function TEST-INSTALL-Scripts
{
    Param($basepath,$Arguments)

    $command = @"
cmd.exe /C msiexec /package `"$basepath`" $Arguments
"@
    Invoke-Expression -Command $command
}

When I try to invoke it via

Invoke-Command -Session $session -ScriptBlock {TEST-INSTALL-Scripts -Basepath $basepath -Arguments $args}

The command doesn't seem to do anything so I tried using a PSRemote tab to try to get some more details and I used this command:

$basepath = "\\$Server\d$\Files\Install\3rd Party\SQL Server Native Client\sqlncli_x64.msi"
$Arguments = '  /quiet /passive'
TEST-INSTALL-Scripts -basepath $basepath -Arguments $Arguments

And I get a response back saying the file cannot be accessed or its not a valid file.

T h i s i n s t a l l a t i o n p a c k a g e c o u l d n o t b e o p e n e d . V e r i f y t h a t t h e p a c k a g e e x i s t s a n d t h a t y o u c a n a c c e s s i t , o r c o n t a c t t h e a p p l i c a t i o n v e n d o r t o v e r i f y t h a t t h i s i s a v a l i d W i n d o w s I n s t a l l e r p a c k a g e .

When I RDP onto the machine itself, the exact same command works without any issue.

My research is pointing toward this being a double hop issue, but short of copying the file to the machine, is there a way of dealing with this that isn't a nightmare?

Xanderu
  • 747
  • 1
  • 8
  • 30
  • 1
    `-ScriptBlock {TEST-INSTALL-Scripts -Basepath $basepath -Arguments $args}` - that won't work; see: https://stackoverflow.com/q/36328690/478656 and https://stackoverflow.com/q/40247384/478656 and linked questions – TessellatingHeckler Sep 26 '17 at 19:53
  • 1
    Also why are you calling `cmd.exe` inside of Powershell `cmd.exe /C msiexec /package \`"$basepath\`" $Arguments` -> `msiexec /package \`"$using:basepath\`" $Arguments` – BenH Sep 26 '17 at 20:28
  • @BenH I'm using cmd because there are some legacy tools I also need to install using cmd and I find it easier to keep the same flow (you are only seeing a trimmed version) – Xanderu Sep 26 '17 at 21:19
  • @TessellatingHeckler I did notice that and fixed it, but the bigger problem is that it throws the permission error when I use PSRemotetab which is essentially the same as a PSSession. I started getting the same error when I fixed passing the Args. – Xanderu Sep 26 '17 at 21:19
  • Then .. duplicate of [Double hop access to copy files without CredSSP](https://stackoverflow.com/questions/15242248/double-hop-access-to-copy-files-without-credssp) because your question is "I don't want to have to deal with security, please can I skip it?" and the answer is "if you could skip it, we could all skip it, and if that were an option, the existing answers wouldn't be a nightmare because nobody would answer with nightmare options if there were easy options" – TessellatingHeckler Sep 26 '17 at 21:36
  • fair enough... I did get a workaround built that is minimal which I'll post – Xanderu Sep 27 '17 at 13:15

1 Answers1

0

I was able to build a minimal workaround that I put in just before the remote call where I pass the install path. I also built a function to make it easier to manager but I put an example IF statement here (I built Get-InstallerLocal which does the same copy based on type)

        If($installPath.StartsWith("\\"))
        {
            $DeployPath = Invoke-Command -Session $session -ScriptBlock {$env:TEMP}
            $drive=(Get-Item $DeployPath).PSDrive.Name
            $localpath = $DeployPath
            $DeployPath = $DeployPath.Replace("$($drive):","\\$machine\$drive$")
            If(!(Test-Path "$DeployPath\3rd Party\Microsoft Visual C++ 2010 Redistributable"))
            {
                Copy-Item -Path "$installPath\3rd Party\Microsoft Visual C++ 2010 Redistributable" -Destination "$DeployPath\3rd Party\Microsoft Visual C++ 2010 Redistributable\" -Force -Recurse
            }
            If($ODBCDriver){Get-InstallerLocal -installPath $installPath -deployPath $DeployPath -Type "SQL Driver"}
            $installPath = $localpath
        }
Xanderu
  • 747
  • 1
  • 8
  • 30