Unable to Copy item from UNC path to destination using $en:programfiles \ (86)

Welcome Forums General PowerShell Q&A Unable to Copy item from UNC path to destination using $en:programfiles \ (86)

Viewing 6 reply threads
  • Author
    Posts
    • #220989
      Participant
      Topics: 4
      Replies: 10
      Points: 51
      Rank: Member
      ###Windows powershell RightScript to install Espera
      
      ##stop and fail script if the software alreday installed##
      if (${env:programfiles(x86)})
        { $advatel_path = join-path "${env:programfiles(x86)}" "Advatel" }
      
      if (test-path $advatel_path)
      {
         Write-Output "Espera already installed. Skipping script"
         read-host โ€œPress ENTER to exit...โ€
         exit 0
         }
      if (${env:programfiles})
        { $advatel_path = join-path "${env:programfiles}" "Advatel" }
      if (test-path $advatel_path)
      {
         Write-Output "Espera already installed. Skipping script"
         read-host โ€œPress ENTER to exit...โ€
         exit 0
      }
      
      ##Prompt for admin credentials before starting##
      Write-Host "Please wait... "  
      $CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) 
      if (($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) -eq $false) 
      { 
          $ArgumentList = "-noprofile -noexit -file "{0}" -Path "$Path" -MaxStage $MaxStage" 
          If ($ValidateOnly) { $ArgumentList = $ArgumentList + " -ValidateOnly" } 
          If ($SkipValidation) { $ArgumentList = $ArgumentList + " -SkipValidation $SkipValidation" } 
          If ($Mode) { $ArgumentList = $ArgumentList + " -Mode $Mode" } 
          Write-Host "elevating" 
          Start-Process powershell.exe -Verb RunAs -ArgumentList ($ArgumentList -f ($myinvocation.MyCommand.Definition)) -Wait 
          Exit 
      } 
      
      #Set-ExecutionPolicy -Scope CurrentUser -Confirm Unrestricted -Verbose
      
      ##Locate the msi files for silent execution##
      $CurrentLocation = Split-Path -Parent $MyInvocation.MyCommand.Path;
      
      ##To install the Espera##
      $msiinstall = @("/i", "EsperaClientSetup.msi", "/q", "/norestart", "/l*v","$env:windir\Temp\espera.log")
      Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList $msiinstall -Wait -WorkingDirectory $CurrentLocation
      
      ##Check IP address to determine which XML file to install
      $IP = ((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
      If('$IP' -like "10.10.*.*") {
      Copy-Item '.\Thh\EsperaClient.exe.config' -Destination "$env:programfiles(x86)"\Advatel\Espera Client\bin  -Recurse -Force
      }Else
      {
         Write-host "Espera Installed"
      }
      stop-process -Id $PID
      
    • #220992
      Participant
      Topics: 4
      Replies: 10
      Points: 51
      Rank: Member

      LINE 48 is where i am having issues with copying from the unc path to destination. I think the issue is the destination part.

    • #220998
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP
      "${env:programfiles(x86)}\Advatel\Espera Client\bin"
    • #221010
      Participant
      Topics: 4
      Replies: 10
      Points: 51
      Rank: Member

      I have tried that with no luck ๐Ÿ™

    • #221016
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      I have tried that with no luck 🙁

      Do you get errors? … I tried it and it outputs exactly the expected result. Did you notice – there is no Dollar sign inside the curly braces. ๐Ÿ˜‰

    • #221031
      Participant
      Topics: 4
      Replies: 10
      Points: 51
      Rank: Member

      Yeah it looks like permissions

      Copy-Item : Access to the path ‘C:\Program Files (x86)\Advatel\Espera Client\bin\EsperaClient.exe.config’ is denied.
      At line:1 char:1
      + Copy-Item ‘.\Thh\EsperaClient.exe.config’ -destination “${env:program …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : PermissionDenied: (\\tpin01\it_dat…ient.exe.config:FileInfo) [Copy-Item], UnauthorizedAccessException
      + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand

      Copy-Item : Access to the path ‘C:\Program Files (x86)\Advatel\Espera Client\bin\EsperaClient.exe.config’ is denied.
      At line:1 char:1
      + Copy-Item ‘.\Thh\EsperaClient.exe.config’ -destination “${env:program …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Copy-Item], UnauthorizedAccessException
      + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.CopyItemCommand

    • #221040
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      Yeah it looks like permissions

      So your issue is not your Powershell code it is your lack of rights to the target folder. ๐Ÿ˜‰

Viewing 6 reply threads
  • You must be logged in to reply to this topic.