cstambaugh
asked on
Powershell script to search domain PC for specific files and output specific results.
Hello,
I am looking to create a Powershell script that will search computers in specified OU and a specified location for specified files, then output that to a csv with the computername, and the files found or not found. I have tried finding multiple scripts that do some of what I wanted, and then merge them, with no avail. Red plagues my screen.
I am trying to understand how it functions as well, because I am not the best at this, and my knowledge can fit on the tip of a ball point pen with Powershell.
I found this one, and I cannot seem to tweak it to work, it searches, but wont write to the csv. I have added several filenames I know are in the PC, and still nothing. I am not sure If I have to format the text a specific way, etc.
Im sure there is a better way. If you wouldnt mind, could you explain the script briefly to me so I can learn instead of having to try and self learn.. Here is one of the examples I tried
EDIT: This does what i want, except I cannot alter it to search for specific OU groups, and I want it to say the computername file not found if it is not found.
ForEach ($system in (Get-Content C:\Users\PATHTOSYSTEMSFILE \systems.t xt)) {
# It's easier to have file path in a variable
$dll = "\\$system\c`$\Windows\Sys WOW64\msxm l3.dll " #Can I use a wildcard here?
$dll = "\\$system\c`$\Windows\Sys WOW64\msxm l6.dll "
# Is the DLL there?
if ( Test-Path $dll){
# Yup, get the version info
$ver = [System.Diagnostics.FileVe rsionInfo] ::GetVersi onInfo($dl l).FileVer sion
# Write file path and version into a file.
Add-Content -path C:\Users\PATHTORESULTS\res ults.csv "$dll,$ver"
}
}
Thank you for your assistance
I am looking to create a Powershell script that will search computers in specified OU and a specified location for specified files, then output that to a csv with the computername, and the files found or not found. I have tried finding multiple scripts that do some of what I wanted, and then merge them, with no avail. Red plagues my screen.
I am trying to understand how it functions as well, because I am not the best at this, and my knowledge can fit on the tip of a ball point pen with Powershell.
I found this one, and I cannot seem to tweak it to work, it searches, but wont write to the csv. I have added several filenames I know are in the PC, and still nothing. I am not sure If I have to format the text a specific way, etc.
Im sure there is a better way. If you wouldnt mind, could you explain the script briefly to me so I can learn instead of having to try and self learn.. Here is one of the examples I tried
EDIT: This does what i want, except I cannot alter it to search for specific OU groups, and I want it to say the computername file not found if it is not found.
ForEach ($system in (Get-Content C:\Users\PATHTOSYSTEMSFILE
# It's easier to have file path in a variable
$dll = "\\$system\c`$\Windows\Sys
$dll = "\\$system\c`$\Windows\Sys
# Is the DLL there?
if ( Test-Path $dll){
# Yup, get the version info
$ver = [System.Diagnostics.FileVe
# Write file path and version into a file.
Add-Content -path C:\Users\PATHTORESULTS\res
}
}
Thank you for your assistance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you It works great!
To run that against multiple OUs in one go, set $computers like this:
$OUList = @(
"ou=INSERTOU1HERE,dc=DCHERE,dc=DCHERE"
"ou=INSERTOU2HERE,dc=DCHERE,dc=DCHERE"
)
$computers = $OUList | ForEach-Object {Get-ADComputer -Filter * -Searchbase $_ | Select-Object -ExpandProperty Name}
ASKER
Great! The next task is to figure out how to add file version information for future uses of this script. Thank you for the assist today.
ASKER
Ok, I have been trying for a few days now to add other properties to the output of this script, like version info, modified date, etc, and cant seem to get it to work.
I am trying to add them here, in this part
by adding another line with @{n='Propertywanted'; But Im not sure what goes afterwards, and why.
Am I going about it all wrong?
I want to add different properties to search for in the script, and understand how it works to adapt it for different situations, like when my boss asks if there is a certain program or version of a file, or when this was installed on this group or that group of PC's, without going to the individual machines.
I didnt want to open a new question, as I figured it wouldnt make much sense without the original content.
Thanks again
I am trying to add them here, in this part
@{n='ComputerName'; e={$computer}},
@{n='FileName'; e={$_}},
@{n='Found'; e={Test-Path -Path "\\$($computer)\$($_.Replace(':', '$'))"}}
by adding another line with @{n='Propertywanted'; But Im not sure what goes afterwards, and why.
Am I going about it all wrong?
I want to add different properties to search for in the script, and understand how it works to adapt it for different situations, like when my boss asks if there is a certain program or version of a file, or when this was installed on this group or that group of PC's, without going to the individual machines.
I didnt want to open a new question, as I figured it wouldnt make much sense without the original content.
Thanks again
ASKER
Basically I want to incorporate this into it somehow.
[System.Diagnostics.FileVe rsionInfo] ::GetVersi onInfo("C: \Windows\P athtofile" ) | Format-List -property *
[System.Diagnostics.FileVe
ASKER
I was in the process of editing and saw it pop up when I was done. I tried thisversion, and it works, except says FALSE on all of the results, even if the file is there.