When there is a situation in Windows, there has to be some solution using PowerShell. So Once again I’ve something useful for you.
SITUATION:
A folder in my Hard disk has about 300 movies and I want to share this list of movie names with my friend, or I want to compare my list with one of my friend’s collection of movies on his hard disk.
SOLUTION:
Below script will work in above situation, you just need to change few parameters in the script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$list = Get-ChildItem -Path 'D:\Movies\' -Recurse | ` | |
Where-Object { $_.PSIsContainer -eq $false -and $_.Extension -ne '.srt' } | |
write-host "`nTotal : "$list.Count "movies `n" | |
ForEach($n in $list){ | |
$n.Name | Out-File -Append 'D:\Movielist.txt' | |
} |
First highlighted parameter is the Directory of the folder, where you want the script to search for movie files, and the second highlighted one is the location of the output file to be placed with name Movielist.txt like below.
If you want to compare two folders for files that aren’t common, for example – I want to compare movies in my laptop with movies in my friends Hard Disk, just add the following script in the above script and modify the highlighted location with the directory to be compared.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$list2 = Get-ChildItem 'F:\FolderInFriendsHDD\'|` | |
Where-Object {$_.PSIsContainer -eq $false -and $_.Extension -ne '.srt'} | |
Compare-Object -ReferenceObject $list -DifferenceObject $list2 -IncludeEqual |
Your output will look something like this :
Happy Learning! 🙂
Related posts
4 Comments
Leave a ReplyCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,131,766 People Reached
can you please help me in writing a script for copying files from one server to another server ? like we can login to a jump server and copy files from within the jump server
Hi Rohit,
just the below cmdlet will work for you.
Copy-Item -Path ‘\Server-01d$prtklogs.txt’ -Destination ‘\Server-02d$’
for more help, Just type
Get-help Copy-Item -full
Awesome!
Will this search sub-folders?