Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3600700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:31:42+00:00 2026-05-18T20:31:42+00:00

I have a table that contains information pointing to files stored on a file

  • 0

I have a table that contains information pointing to files stored on a file server. I’m trying to write a powershell script to verify that each record in the table has a physical file associated with it on the server, if it does not write to the CSV file. I’m not having much luck wit the csv portion and was hoping you could help?

Here is what I have so far (please let me know if there are better ways to do this, Im brand new to powershell). I only want to add records to the csv if the test-path fails to find the file in question.

[Reflection.Assembly]::LoadFile("C:\ora10g\odp.net\bin\2.x\Oracle.DataAccess.dll")
$connectionString = "Data Source=XXXXXX;User Id=XXXX;Password=XXXXXXXX;"
$connection = New-Object Oracle.DataAccess.Client.OracleConnection($connectionString)
$connection.Open()
$queryString = "SELECT Key, Sequence, Type, File FROM FileTable WHERE Type IN (2, 5)"

$command = new-Object Oracle.DataAccess.Client.OracleCommand($queryString, $connection)
$mediaObjRS = $command.ExecuteReader()

# Loop through recordset
while ($mediaObjRS.read()) {

   # Assign variables from recordset.
   $objectKey = $mediaObjRS.GetString(0)
   $objectSeq = $mediaObjRS.GetDecimal(1)
   $objectType = $mediaObjRS.GetDecimal(2)
   $objectFileName = $mediaObjRS.GetString(3)

        # Check if file exists based on filetype.
        if($objectType -eq 2){
            # Type 2 = OLE
            $fileLocation = "\\fileserver\D$\files\" + $objectFileName
        }elseif($objectType -eq 5){ 
             # Type 5 = FILE
             $fileLocation = $objectFileName        
        }
        $fileExists = Test-Path $fileLocation
        if($fileExists -eq $False){
                #Write to output file
                $objectKey | Export-Csv missingfiles.csv
                $objectSeq | Export-Csv missingfiles.csv
                $objectType | Export-Csv missingfiles.csv
                $objectFileName | Export-Csv missingfiles.csv
        }
}

$connection.Close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:31:43+00:00Added an answer on May 18, 2026 at 8:31 pm

    Each time you write to the missingfiles.cs you clobber the previous one. Plus this cmdlet is oriented towards saving objects where each property represents one of the comma separated values.

    The simplest way to do this is to manually write (append) to the csv file:

    if(!$fileExists) {
        #Write to output file
        "`"$objectKey`",`"$objectSeq`",`"$objectType`",`"$objectFileName`" >> foo.csv
    }
    

    The “slick” PowerShell way to do it would be to create an object for each file and then put those in an array and when you’re done, export that array of object to a CSV file e.g.:

    $files = @() # Initialize array outside loop
    ...
    if (!$fileExists) {
        $obj = new-object -psobject -prop @{
                   Key = $objectKey
                   Seq = $objectSeq
                   Type = $objectType
                   FileName = $objectFileName
               }
        $files += obj
    }
    ...
    # outside of loop, export array of objects to csv
    $files | Export-Csv missingfiles.csv
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains information pointing to files stored on a file
I have a table that contains file paths, like so: -------------------- |Files | --------------------
I have a table (user) that contains user information. I have another table (userview)
I have two tables: a schedule table that contains information about how an employee
I have a jsp that contains a table with some information from db. I
I have a table in Oracle 10g that contains some information as follows: SQL>
I have a table that contains information on groups. There can be any number
Suppose that I have a database table that contains information on cities across the
I have a table that contains the following information date sales 2011-02-13 1 2011-02-13
I have a table with that contains information that I would like to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.