Powershell script to find files in restricted folders (other user folders)
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.
$filePath = "c:"
$fileName = "somefile"
$Computer = Get-Content env:computername
$srvpath = "\\server\share$\FindFileScript\$Computer.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
}
1) We are using 3rd party program that can deploy programs and launch
powershell script as well.
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.
Is there a way to force search on restricted folders as well?
2) Second question is not so important but is it possible somehow to
include in $filePath not only C: but D: as well?
No comments:
Post a Comment