title: How to Call Powershell Copy-Script from VBS Logon Script
body: <p>I am currently in the process of converting a logon script from VBS to Powershell, and one of the subs, which updates a specific file if it is an older version, has been reduced to this:</p>
  <pre><code>sub UrgentSupportApp()
      On Error Resume Next
  
      Set objShell = CreateObject(&quot;WScript.Shell&quot;)
      objShell.Run &quot;powershell -file &quot;&quot;\\DC1\NETLOGON\PSSubs\UrgentSupportApp.ps1&quot;&quot;&quot;, 0, true
  
      If Err &lt;&gt; 0 Then
          strMessage = &quot;ERROR: Sub - UrgentSupportApp&quot;
          DisplayCustomError(strMessage)
      End If
  End Sub
  </code></pre>
  <p>But when I log in I am seeing this error:</p>
  <blockquote>
  <p>Number (dec) : -2147352567</p>
  <p>Number (hex) : &amp;H80020009</p>
  <p>Description  : Unable to wait for process.</p>
  <p>Source       : WshShell.Run</p>
  </blockquote>
  <p>I know the powershell works, as I have tested it as a standalone script. However, I am not sure if accessing it over the network has implications for the <code>env:USERPROFILE</code> variable (which user is in scope here?).</p>
  <p>I tried changing the <code>bWaitOnReturn</code> parameter to <code>false</code>, and this resulted in no errors, but the script didn't actually do the work.</p>
  <p>Does anyone have any tips as to how I can debug this or what might be going wrong?</p>
  <p>The ps1 script looks like this:</p>
  <pre><code>$appsource = '\\file\Administration\Unused\Apps\IT Support App\IT Self Help.exe'
  $apptarget = $env:USERPROFILE + '\desktop\IT Self Help.exe'
  
  $oldapp1 = $env:USERPROFILE + '\desktop\Urgent IT Help Request.exe'
  $oldapp2 = $env:USERPROFILE + '\desktop\IT Help Request.exe'
  
  $currentversion = (Get-Command $appsource).FileVersionInfo.FileVersion
  
  If (Test-Path $oldapp1) {Remove-Item $oldapp1}
  If (Test-Path $oldapp2) {Remove-Item $oldapp2}
  
  If (Test-Path $apptarget) {
      If (!((Get-Command $apptarget).FileVersionInfo.FileVersion -eq $currentversion)) {
          Copy-Item $appsource $env:USERPROFILE'\desktop' -Force
      }
  }
  Else {Copy-Item $appsource $env:USERPROFILE'\desktop' -Force}
  </code></pre>
  <p>It simply removes any of the files which have the old name, and then copies over the newest version if it doesn't already exist.</p>