Processing
 

Script Complains that File Cannot be Found When not Looking for it

15/09/2016 13:39#1

Bassie

Member

Joined at: 10 months ago

Post: 14

Thank: 0

Thanked: 0

I have the below function running in a logon script, which checks whether the user has the current version of IT Self Help.exe. If the current version is not present, then it should be copied onto the desktop from the $appsource folder:

function UrgentSupportApp {     $ErrorActionPreference = "Stop"     trap {Log-Error $_ $MyInvocation.MyCommand; Return}      $desktop = $env:USERPROFILE + '\Desktop\'     $apptarget = $desktop + 'IT Self Help.exe'     $appsource = '\\file\Administration\Unused\Apps\IT Support App\IT Self Help.exe'      # Remove the old version of the app "IT Help Request.exe"     $oldapps = Get-ChildItem $desktop -Filter *"Help Request.exe"     if ($oldapps.count -gt 0) {Remove-Item $oldapps.PSPath -Force}      # Copy the new version over if it is not already present     $currentversion = (Get-Command $appsource).FileVersionInfo.FileVersion      if (Test-Path $apptarget) {         if ((Get-Command $apptarget).FileVersionInfo.FileVersion -ne $currentversion) {             Copy-Item $appsource $desktop -Force  ##### Line 981 #####         }     } else {         Copy-Item $appsource $desktop -Force     } } 
function Log-Error {     param (         $error,         [string]$sub,         $detail     )     $ErrorActionPreference = "Stop"     trap {Log-Error $_ $MyInvocation.MyCommand; Return}      $filename = "\\file\administration\Unused\LogonScriptErrors\$username - $sub - $computername - $(Get-Date -Format ddMMyyyy-HHmmss).log"      New-Item $filename -ItemType File -Value "Message: `r`n`t $($error.Exception.Message) `r`n `r`nPosition: `r`n`t $($error.InvocationInfo.PositionMessage) `r`n `r`nSub: `r`n`t $sub `r`n `r`nDetail: `r`n`t $detail" } 

For a couple of users, I am seeing this error come through on line 981, char 22 (see the comment above):

Could not find file 'C:\Users\USER.NAME\Desktop\IT Self Help.exe'.  At \\DC\NETLOGON\mainlogon.ps1:981 char:22 +             Copy-Item <<<<  $appsource $desktop -Force

However

  • The file clearly can be found, as it made it through the fisrt If condition If (Test-Path $apptarget).
  • If the file couldn't be found, why would the script complain on that line, where we are not even looking for it?

What is this error trying to tell me? If the file could not be found, surely the script would just continue into the Else statement

Similar articles

How to use Logstash with log4j in Windows 7 32-bit VM

5 months ago - Reply: 1 - Views: 136

Running webrick server in background for Windows

5 months ago - Reply: 0 - Views: 60

Task Scheduler doesn't start my exe for the next day

5 months ago - Reply: 0 - Views: 47

Unable to get Windows Updates in Windows 7 [on hold]

5 months ago - Reply: 0 - Views: 27

Connect Spark-Shell using Eclipse in Windows 7

5 months ago - Reply: 0 - Views: 28

Can't use custom windows themes

5 months ago - Reply: 1 - Views: 117

“npm install <module>” doesn't work

5 months ago - Reply: 0 - Views: 41

OpenGL 4.5 functions segfaulting

5 months ago - Reply: 0 - Views: 6

Executing a batch file during installation

5 months ago - Reply: 0 - Views: 3

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re