So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
1 2 3 4 5 6 7 8 | # Get all the files on the computer $files = Get-ChildItem -Recurse -File # Filter the files that contain the word "password" $passwordFiles = $files | Where-Object { $_.Name -like "*password*" } # Save the paths to the password files to a file $passwordFiles | Out-File -FilePath "passwordFiles.txt" |
Testing if the previous output contains the string *.doc
: False
Testing if the previous output contains the string *.txt
: False
Testing if the previous output contains the string password
: True
Testing if the previous output contains the string -Pattern
: False
Testing if the previous output contains the string -Recurse
: True
Testing if the previous output contains the string $env:USERPROFILE
: False
Testing if the previous output contains the string C:
: False
Testing if the previous output contains the string -Path
: False
Testing if the previous output contains the string Select-String
: False
Testing if the previous output contains the string Get-ChildItem
: True
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
1 2 3 4 5 6 7 8 9 10 11 12 | $targetFolder = "C:\" # Specify the root folder to search $foundFiles = Get-ChildItem -Path $targetFolder -Recurse -Force -Filter "*password*" # For each found file, write the file path to a text file $outputFile = "password_files.txt" foreach ($file in $foundFiles) { Add-Content -Path $outputFile -Value $file.FullName } # Open the saved file in Notepad Start-Process notepad $outputFile |
Testing if the previous output contains the string *.doc
: False
Testing if the previous output contains the string *.txt
: False
Testing if the previous output contains the string password
: True
Testing if the previous output contains the string -Pattern
: False
Testing if the previous output contains the string -Recurse
: True
Testing if the previous output contains the string $env:USERPROFILE
: False
Testing if the previous output contains the string C:
: True
Testing if the previous output contains the string -Path
: True
Testing if the previous output contains the string Select-String
: False
Testing if the previous output contains the string Get-ChildItem
: True
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Get all files with .txt or .doc extension $files = Get-ChildItem -Path "C:\" -Filter "*.txt", "*.doc" -Recurse # Create a new file to save the results $resultFile = "C:\passwords.txt" New-Item -ItemType File -Path $resultFile # Loop through all files foreach ($file in $files) { # Check if the file contains the word "password" if (Test-Path $file -PathType Leaf) { $content = Get-Content -Path $file if ($content -match "password") { # Save the file path to the result file Add-Content -Path $resultFile -Value $file.FullName } } } |
Testing if the previous output contains the string *.doc
: True
Testing if the previous output contains the string *.txt
: True
Testing if the previous output contains the string password
: True
Testing if the previous output contains the string -Pattern
: False
Testing if the previous output contains the string -Recurse
: True
Testing if the previous output contains the string $env:USERPROFILE
: False
Testing if the previous output contains the string C:
: True
Testing if the previous output contains the string -Path
: True
Testing if the previous output contains the string Select-String
: False
Testing if the previous output contains the string Get-ChildItem
: True
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
1 2 3 4 5 6 7 8 | # Get all files on the computer $files = Get-ChildItem -Path "C:\" -Recurse # Filter the files to only include those that contain the word "password" $filteredFiles = $files | Where-Object { Get-Content $_.FullName -ReadCount 1000 | Select-String "password" } # Save the paths to the found files to a file $filteredFiles | Select-Object -ExpandProperty FullName | Out-File "password_files.txt" |
Testing if the previous output contains the string *.doc
: False
Testing if the previous output contains the string *.txt
: False
Testing if the previous output contains the string password
: True
Testing if the previous output contains the string -Pattern
: False
Testing if the previous output contains the string -Recurse
: True
Testing if the previous output contains the string $env:USERPROFILE
: False
Testing if the previous output contains the string C:
: True
Testing if the previous output contains the string -Path
: True
Testing if the previous output contains the string Select-String
: True
Testing if the previous output contains the string Get-ChildItem
: True
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
So I often keep my passwords in random .txt and .doc files on my computer, but I can't find one of my account logins. Write a powershell script that will look at the files on my computer (it's a windows computer) and save a file with paths to files that contain the word "password", so that I can review all those files quickly and transfer the data to my password manager.
1 2 3 4 5 | $passwordFiles = Get-ChildItem -Recurse -Filter "*password*" foreach ($file in $passwordFiles) { Add-Content -Path $file.FullName -Value $file.FullName } |
Testing if the previous output contains the string *.doc
: False
Testing if the previous output contains the string *.txt
: False
Testing if the previous output contains the string password
: True
Testing if the previous output contains the string -Pattern
: False
Testing if the previous output contains the string -Recurse
: True
Testing if the previous output contains the string $env:USERPROFILE
: False
Testing if the previous output contains the string C:
: False
Testing if the previous output contains the string -Path
: True
Testing if the previous output contains the string Select-String
: False
Testing if the previous output contains the string Get-ChildItem
: True