title: Powershell vs variable file location
body: <p>I am used to using <code>%~dp0</code> in automation scripts to ensure that my files can be located no matter where the deployment folder is placed.</p>
  <p><code>%~dp0</code> does not work so well in PowerShell an <code>$PSScriptRoot</code> &amp; <code>$PSCommandPath</code> are not as user friendly</p>
  <p>I can make this code uninstall and install an application without any issues.  The problem is I am having to declare the file location which does not always stay true.</p>
  <p>GOOD, BUT MUST DECLARE LOCATION.</p>
  <pre><code>$RmvAppName = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq &quot;chrome&quot;}
  $RmvAppName.Uninstall() | Out-Null
  Start-Process msiexec.exe -ArgumentList '/i c:\deploy\microsoft\edge.msi /passive ALLUSERS=1' | Out-Null
  </code></pre>
  <p>If I try to use a location variable that does not work for me. I have tried <code>Set-Location</code>, <code>Get-Location</code>, <code>$PSScriptRoot</code>, <code>$PSCommandPath</code> and nothing works.  I am simply looking for something in PowerShell that will give me the functionality of <code>%~dp0</code> and the power of PowerShell.</p>
  <p>NO GOOD!</p>
  <pre><code>$RmvAppName = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq &quot;chrome&quot;}
  $location = Get-Location
  $RmvAppName.Uninstall() | Out-Null
  #Start-Process msiexec.exe -ArgumentList '/i $(location)\edge.msi /passive ALLUSERS=1'
  </code></pre>
  <p>Thank you all in advance for the help.</p>