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

  • Home
  • SEARCH
  • 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 8545531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:48:45+00:00 2026-06-11T12:48:45+00:00

I’m trying to write a PowerShell script that will generate a table of information

  • 0

I’m trying to write a PowerShell script that will generate a table of information with two columns: a name, and a date (which will be retrieved from a third-party application – in this case svn.exe).

The overall script works well, but I’m struggling to get the date that the server sends back into the DataTable. Here’s a simplified version of my script:

# Set up a DataTable and initialise columns
$table = New-Object system.Data.DataTable “Test Table”
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn DateFromServer,([DateTime])
$table.columns.add($col1)
$table.columns.add($col2)

# Create a new row and add the data
$row = $table.NewRow()
$row.Name = "Test"
$lastCommit = GetDateFromExternalApp
$lastCommit.GetType() # this returns DateTime as I would expect
$row.DateFromServer = $lastCommit # this throws up an error
$table.Rows.Add($row)

# Output the table
$table | Format-Table -AutoSize

# This function simulates what the actual function does
# (the real one goes to SVN and pulls down data, but it
# ends up with the same resulting date)
Function GetDateFromExternalApp
{   
    $externalAppDate = "2012-09-17T16:33:57.177516Z"

    return [DateTime]($externalAppDate)
}

The problem (noted in comments in the script above) is that while the function seems to be happily returning a DateTime instance, when I try to add this into the table row’s DateFromServer column it’s throwing up an error:

Exception setting "DateFromServer": "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <18/09/2012 2:33:57 AM> in DateFromServer  Column.  Expected type is DateTime." At line:13 char:6
+ $row. <<<< DateFromServer = $lastCommit
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

However, the call to $lastCommit.GetType() shows that this is indeed a DateTime – and in fact if I add this line somewhere in the script:

$lastCommit

then I can see a nicely formatted datetime, suggesting that it is indeed parsing it and converting it correctly:

Date        : 18/09/2012 12:00:00 AM
Day         : 18
DayOfWeek   : Tuesday
DayOfYear   : 262
Hour        : 2
Kind        : Local
Millisecond : 177
Minute      : 33
Month       : 9
Second      : 57
Ticks       : 634835324371775160
TimeOfDay   : 02:33:57.1775160
Year        : 2012
DateTime    : Tuesday, 18 September 2012 2:33:57 AM

As such I’m quite puzzled as to why I’m getting the exception above. I realise that PowerShell does function return values differently than C#, but it looks to me like the function is returning the right type!

  • 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-06-11T12:48:46+00:00Added an answer on June 11, 2026 at 12:48 pm

    I’d like to know the reason for this behaviour too.

    Anyway, you can work around the problem by casting the date variable as DateTime or by explicitly declaring it to be one. Like so,

    ...
    $row.DateFromServer = [DateTime]$lastCommit # Doesn't throw exception
    ...
    

    Or

    ...
    [DateTime]$lastCommit = GetDateFromExternalApp
    $row.DateFromServer = $lastCommit # Doesn't throw exception
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small

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.