search for file type in a date range using powershell remotely

how can I search for say *.jpg on a remote system from say 8-12 to 8-18 ?
I was thinking something along these lines but not sure how to pass credentials and all
dir "c:\" | ? {$_.PSIsContainer} | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | ConvertTo-Html Name | Set-Content c:\tony\new_Media.htm

Open in new window


thanks
bbimisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JAN PAKULAICT Infranstructure ManagerCommented:
save your script and run it on the remote computer using psexec


http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
0
footechCommented:
You can either access the remote machine via UNC path, or you can use PowerShell Remoting.
You wouldn't use ? {$_.PSIsContainer} as that would only give you folders.
If you have a lot of machines, PS Remoting is by far the better solution in terms of speed, but it takes some setup.  If you just have one or a few machines, accessing via the UNC only requires admin permissions and ports opened for file sharing.
Get-ChildItem \\remotecomp\c$ -filter *.jpg -recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}

Open in new window

If you needed to specify an upper-limit to the date range that is less than the current time, then you would just need to add another condition to the Where-Object scriptblock.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbimisAuthor Commented:
exactly what I was looking for. thanks. I modified it for my needs but this is what I was looking for. Thanks again!
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

bbimisAuthor Commented:
one question how can I use the -Credential parameter with this
function find_file {
param ( $RemoteComputer = $compname )
$searchfor = Read-Host "What would you like to search for? Wild cards excepted"
  $output = Get-ChildItem \\$RemoteComputer\c$ -filter  $searchfor -recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | Format-List
  $output | Out-File "filesearch results for $RemoteComputer.txt"
  }

Open in new window


like on other functions I have its like this
function Get-IPConfig{

param ( $RemoteComputer= $compname,

  $OnlyConnectedNetworkAdapters=$true

   )

gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $RemoteComputer -Credential $creds | Where { $_.IPEnabled -eq $OnlyConnectedNetworkAdapters } | Format-List @{ Label="Computer Name"; Expression= { $_.__SERVER }}, IPEnabled, Description, MACAddress, IPAddress, IPSubnet, DefaultIPGateway, DHCPEnabled, DHCPServer, DNSServerSearchOrder, @{ Label="DHCP Lease Expires"; Expression= { [dateTime]$_.DHCPLeaseExpires }}, @{ Label="DHCP Lease Obtained"; Expression= { [dateTime]$_.DHCPLeaseObtained }}

} 

Open in new window

0
bbimisAuthor Commented:
I keep getting this error
error i get
when using this
function find_file {
    param ( $RemoteComputer = $compname)
    $credits = Get-Credential
    $searchfor = Read-Host "What would you like to search for? Wild cards excepted"
    $output = Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {
                    Get-ChildItem \\$RemoteComputer\c$ -filter  $searchfor -recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | Format-List
                    } -Credential $credits
     $output | Out-File "filesearch results for $RemoteComputer.txt"
       
  }

Open in new window

0
footechCommented:
Since Get-ChildItem doesn't support the -credential parameter, the only way you could use the code in http:#a40270200 would be to launch the PS console using different credentials.

In http:#a40270254, that is using PS Remoting.  It is an option but needs to be enabled.  Typically you would use something like:
function find_file {
    param ( $RemoteComputer = $compname)
    $credits = Get-Credential
    $searchfor = Read-Host "What would you like to search for? Wild cards excepted"
    $output = Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {
                    Get-ChildItem c:\ -filter  $searchfor -recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | Format-List
                    } -Credential $credits
     $output | Out-File "filesearch results for $RemoteComputer.txt"
       
  }

Open in new window

You wouldn't have the session be on the remote computer and use that computer's UNC path at the same time.

One other option is to use Invoke-Command to create a session on the local machine using different credentials, and then query the UNC path.  This would have to be run from an elevated session in order to use Invoke-Command to the local machine.
function find_file {
    param ( $RemoteComputer = $compname)
    $credits = Get-Credential
    $searchfor = Read-Host "What would you like to search for? Wild cards excepted"
    $output = Invoke-Command -ComputerName localhost -ScriptBlock {
                    Get-ChildItem \\$RemoteComputer\c$ -filter  $searchfor -recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-7)} | Format-List
                    } -Credential $credits
     $output | Out-File "filesearch results for $RemoteComputer.txt"
       
  }

Open in new window


Last note - if you're just going to output to a file, there's no reason to first store the result in a variable like $output, just pipe straight to Out-File.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.