I am having an issues with copying an item to a remote computer. I am using credentials for a domain admin to push remote installs. I am able to run this file locally however trying to push MSI file from a remote location it errors out. So i wanted to copy the file locally and run the file from there. I copied the file manually and tested my code and the msi file installs correctly however I am unable to have power shell copy the file automatically.
I have tried using quotes and escaping the spaces with no change.
Please see code below;
Function Install-MSI
{
Write-Host "Installing MSI Files..."
$oSession = New-PSSession -ComputerName $sComputer -Credential $oCerdentials
$sResults = Invoke-Command -Session $oSession -ScriptBlock {
$Source = "\\Servername\Folder1\Folder 2\Folder3\Folder 4\File Name with Spaces (64-bit).msi"
Copy-Item -Path $Source -Destination C:\Users\User\Desktop\
Start-Process MSIExec "/i `"C:\Users\User\Desktop\File Name with Spaces (64-bit).msi`" /passive /norestart /lv C:\Users\User\Desktop\log.txt"
}
}
Error
Cannot find path '\\Servername\Folder1\Folder 2\Folder3\Folder 4\File Name with Spaces (64-bit).msi' because it does not exist.
+ CategoryInfo : ObjectNotFound: (\\Servername...es (64-bit).msi:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand