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 6996951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:13:19+00:00 2026-05-27T20:13:19+00:00

I have powershell version 2.0.0.1082 on my server. I want to import data from

  • 0

I have powershell version 2.0.0.1082 on my server. I want to import data from a text file to SQL server, and add two new fields (character and current datetime) to the input to SQL 2008 database. I have been using bulk import or SSIS to do it but I want to use powershell for the ease of maintaining the process. The file has column name at top and each field is seperated by “|”.
Code so far:

clear

 import-csv "Disk.txt" -Delimiter "|" | 
 foreach { add-member -in $_ -membertype noteproperty DateRecorded $((Get-Date).ToString("yyyy-MM-dd")) 
 add-member -in $_ -membertype noteproperty SystemName 'System Name'
 add-member -in $_ -membertype noteproperty Drive 'Drive Letter'
 add-member -in $_ -membertype noteproperty TotalSizeGB 'Total Size'
 add-member -in $_ -membertype noteproperty UsedGB Used
 add-member -in $_ -membertype noteproperty FreeGB Free
 add-member -in $_ -membertype noteproperty PercentFree '% Free'}|
select DateRecorded,SystemName,Drive,TotalSizeGB,UsedGB,FreeGB,PercentFree |Format-Table

Any ideas please?

Thanks!

Manjot

  • 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-27T20:13:20+00:00Added an answer on May 27, 2026 at 8:13 pm

    You’ll either need to add the -PassThru switch to the Add-Member cmdlet to forward the objects on in the pipeline or put $_ all by itself at the end of the ForEach block.

    Here is an example using -PassThru:

    Import-Csv "Disk.txt" -Delimiter "|" | ForEach {
        Add-Member -InputObject $_ -MemberType NoteProperty -name "DateRecorded" -value $((Get-Date).ToString("yyyy-MM-dd"))
        Add-Member -InputObject $_ -MemberType NoteProperty -name "SystemName" -value 'System Name' -PassThru
    } | Select DateRecorded,SystemName,Drive,TotalSizeGB,UsedGB,FreeGB,PercentFree | Format-Table
    

    Another example without -PassThru:

    Import-Csv "Disk.txt" -Delimiter "|" | ForEach {
        Add-Member -InputObject $_ -MemberType NoteProperty -name "DateRecorded" -value $((Get-Date).ToString("yyyy-MM-dd"))
        Add-Member -InputObject $_ -MemberType NoteProperty -name "SystemName" -value 'System Name'
        $_
    } | Select DateRecorded,SystemName,Drive,TotalSizeGB,UsedGB,FreeGB,PercentFree | Format-Table
    

    Once you’ve prepared your CSV data for input into the database you can use the Invoke-SqlCmd cmdlet that comes with SQL Server 2008 to perform Inserts. There is a wealth of information on MSDN here to show you how.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following XML file, and I want to use PowerShell (version
I have a file that I set using PowerShell that contains the version number
I just tested an early PowerShell WPF example from here #requires -version 2 Add-Type
I have exported data from an EventLog using PowerShell and have created a sample
Basic powershell question here - I have two computers in the c:\temp\servers.txt file and
I am trying to have PowerShell unblock a file in Win2K8 R2. Does anyone
I have a Powershell script that copies files from one location to another. Once
How do I have a PowerShell script embedded within the same file as a
I have a complex Powershell script that gets run as part of a SQL
I have a powershell script that is replacing patterns in a file with the

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.