First, I'd like to thank Jakub for fixing my account. I'm a first time poster and novice Powershell user. I have a script that gets hardware resources like hard drive info. I'm updating it to search for folder and output the folder name to Excel. Jakub helped me accomplish this. However, When the hard drive query runs and finds another drive, the output of the folder name for Oracle repeats on the 2nd line of the csv file.
$colDisks = get-wmiobject "Win32_LogicalDisk" -namespace "root\CIMV2" –computername $i -Filter "DriveType = 3"
foreach($Cdisk in $colDisks){
$CdeviceID = $Cdisk.DeviceID
$size = [math]::round($Cdisk.Size /1024/1024/1024,0)
$Cfreespace = [math]::round($Cdisk.FreeSpace / 1024/1024/1024,0)
if (Test-Path \\$i\C$\Oracle\product)
{
$colCOracle = (invoke-command -computername $i {Get-ChildItem -Path c:\oracle\product | Select-Object -ExpandProperty FullName})-join ", "
}
else
{
$colCOracle="Oracle does not exist in C drive"
}
if (Test-Path \\$i\D$\Oracle\product)
{
$colDOracle = (invoke-command -computername $i {Get-ChildItem -Path d:\oracle\product | Select-Object -ExpandProperty FullName})-join ", "
}
else
{
$colDOracle="Oracle does not exist in D drive"
}
$o = new-object PSObject
$o|add-member NoteProperty OracleClients $colCOracle`r`n$colDOracle
$o|export-csv "Results.csv" -notypeinformation -append
The CSV shows below. How can I modify my current script to show the output only if it finds \oracle\product on the drive it was found from, instead of repeating the output?
| Storage | Size (GB) | FreeSpace (GB) | OracleClients |
| C: | 75 | 54 | Oracle does not exist in C drive D:\oracle\product\11.2.0.4, D:\oracle\product\11.2.0.4_32b |
| D: | 75 | 66 | Oracle does not exist in C drive D:\oracle\product\11.2.0.4, D:\oracle\product\11.2.0.4_32b |