I need to produce a list of files stored on multiple remote computer desktops.
Can some provide a powershell script so i can do this from my computer.
Technology Tips and News
I need to produce a list of files stored on multiple remote computer desktops.
Can some provide a powershell script so i can do this from my computer.
You will use Get-ChildItem, and since you are doing remote computers you will need to be an Administrator as you will need to access the admin shares
Get-Help Get-ChildItem -Full
# Example Get-ChildItem \\computername\c$\SomeFolder -Recurse
in addition to clyman2s post, something like this:
$Computers = 'localhost', 'Computer2' foreach ($Computer in $Computers){ $Users = (Get-ChildItem -Path \\$Computer\C$\Users).Name foreach ($User in $Users){ Get-ChildItem -Path \\$Computer\C$\Users\$User\Desktop -Recurse } }
it's up to you, how you want to format it
And with the following you will retrieve the loggedon User.
$Computers = 'localhost' foreach ($Computer in $Computers){ #Gets the logged on user $User = Get-WmiObject win32_logonsession -ComputerName $Computer -Filter "Logontype = '2' or Logontype='11' or logontype='10'" | foreach {Get-WmiObject win32_loggedonuser -ComputerName $Computer -filter "Dependent = '\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=`"$($_.logonid)`"'" | select Antecedent } | foreach { ($_.antecedent.split('"'))[1] + "\" + ($_.antecedent.split('"'))[3] } | select -unique #Catches Domain name if ($user -like "*\*") { $user = $user.Split('\')[-1] } $searchPath="\\$Computer\C$\Users\$User\Desktop\" Get-ChildItem -Path $searchPath -Recurse }
What if I wanted to get your second script to read the computer names from a single text or CSV file and then export the information to a text or CSV file for example. How would I do that?
Use Get-Content to read a text file or Import-Csv for a CSV file. Use ForEach-Object to process each item, then use Export-Csv outside of the loop to export your results out to a CSV file.
Syntax/examples:
http://ss64.com/ps/get-content.html
http://ss64.com/ps/import-csv.html
I have tried the first part of trying to read from a CSV file but i am getting the error below.
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum ent is null or empty. Supply an argument that is not null or empty and then try the command again. At line:3 char:59 + $User = Get-WmiObject win32_logonsession -ComputerName <<<< $Computer -F ilter "Logontype = '2' or Logontype='11' or logontype='10'" | + CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi ngValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power Shell.Commands.GetWmiObjectCommand Get-ChildItem : Cannot find path '\\\C$\Users\\Desktop\' because it does not ex ist. At line:12 char:18 + Get-ChildItem <<<< -Path $searchPath -Recurse + CategoryInfo : ObjectNotFound: (\\\C$\Users\\Desktop\:String) [ Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCh ildItemCommand
Script:
$Computers = Import-Csv c:\computers.csv foreach ($item in $Computers){ #Gets the logged on user $User = Get-WmiObject win32_logonsession -ComputerName $Computer -Filter "Logontype = '2' or Logontype='11' or logontype='10'" | foreach {Get-WmiObject win32_loggedonuser -ComputerName $Computer -filter "Dependent = '\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=`"$($_.logonid)`"'" | select Antecedent } | foreach { ($_.antecedent.split('"'))[1] + "\" + ($_.antecedent.split('"'))[3] } | select -unique #Catches Domain name if ($user -like "*\*") { $user = $user.Split('\')[-1] } $searchPath="\\$Computer\C$\Users\$User\Desktop\" Get-ChildItem -Path $searchPath -Recurse }
Hi,
how does your csv look like?
$Computers = Import-Csv c:\computers.csv foreach ($Computer in $Computers){ #Gets the logged on user $User = Get-WmiObject win32_logonsession -ComputerName $Computer -Filter "Logontype = '2' or Logontype='11' or logontype='10'" | foreach {Get-WmiObject win32_loggedonuser -ComputerName $Computer -filter "Dependent = '\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=`"$($_.logonid)`"'" | select Antecedent } | foreach { ($_.antecedent.split('"'))[1] + "\" + ($_.antecedent.split('"'))[3] } | select -unique #Catches Domain name if ($user -like "*\*") { $user = $user.Split('\')[-1] } $searchPath="\\$Computer\C$\Users\$User\Desktop\" Get-ChildItem -Path $searchPath -Recurse }
My CV just contains one computer name at the moment for example:
computer1