Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help with tweaking script to send output to csv file

$
0
0

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?

StorageSize (GB)FreeSpace (GB)OracleClients
C:7554Oracle does not exist in C drive

D:\oracle\product\11.2.0.4, D:\oracle\product\11.2.0.4_32b
D:7566Oracle does not exist in C drive

D:\oracle\product\11.2.0.4, D:\oracle\product\11.2.0.4_32b

Viewing all articles
Browse latest Browse all 6937

Trending Articles