title: Powershell script to find files in restricted folders (other user folders)
body: <p>I'm making a script which would search for a file. If file is found it will write txt file on server with computer's name and path where file is located.</p>
  
  <pre><code>$filePath = "c:"
  $fileName = "somefile"
  $computerName = Get-Content env:computername
  $srvPath = "\\server\share$\FindFileScript\$computerName.txt"
  
  #SEARCH FOR FILE ON C DISK
  $fileResult = (Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue
  | Where-Object { $_.Name -like "*$fileName*" } | Select-Object FullName | format-Table * -AutoSize)
  if ($fileResult -eq $Null)
  {
  Write-Host "File named $fileName on disk C was not found."
  }
  Else
  {
  Write-Host "File named $fileName on disk C was found."
  Out-File -FilePath $srvPath -InputObject $fileResult
  }
  </code></pre>
  
  <p>1) We are using 3rd party program that can deploy programs and launch powershell script as well.</p>
  
  <p>The problem  is though that program launch script as Administrator user so powershell script is not allowed to search for files on C:\Users[some_other_user] folder.</p>
  
  <p>Is there a way to force search on restricted folders as well?</p>
  
  <p>2) Second question is not so important but is it possible somehow to include in $filePath not only C: but D: as well?</p>
  
  <p>======================================
  EDIT:
  Ok, I think the problem now is even worse. It doesn't search not only user folder but C disk at all... by some reason I didn't notice this.</p>
  
  <p>So problem is not with powershell script but with 3rd party deployment tool. When launching script manually on physical computer it works.</p>
  
  <p>So I'd better find a way how to launch this script in other way, is there other way I could launch this script for users?</p>
  
  <p>I tryed on local machine from cmd.exe:</p>
  
  <pre><code>powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
  </code></pre>
  
  <p>It returned search results on D: and I: only but ignored C:</p>
  
  <p>======================================EDIT2:
  I start Powershell as normal user copy-paste the script and it works, it finds a file on C disk!</p>
  
  <p>If I start Powershell as administrator copy-paste script then it doesn't work, it doesn't find a file on C disk.</p>