0

In Powershell, I am doing a SQL query for a single row of data. Lets say $data for example.

The response from the query a System.Data.DataSet type. Within it, there is a tables property that has the data I need.

$data.Tables

ServerName          : Server15
SamAccount          : Admin-Server15
LastPWDReset        : 1/15/2019 12:00:00 AM
LastPWDResetAttempt : 

I don't intend to write this data back out of anything. Instead, I want to display it, and convert the empty "LastPWDResetAttemp" to "NONE" where it is blank.

I thought it would be done like this:

 $data.Tables.lastPWDResetAttempt = "None"

but that gives me an error The property 'lastPWDResetAttempt' cannot be found on this object. Verify that the property exists and can be set.

I can't help but think I am missing some conversion from "Dataset" to "String".

I've tried to-string but in doing so, I ended up with just a string of data and not the headings. Nothing I could update, or easily use to build my eventual table.

My work around:

$webdata = "" | select ServerName,SamAccount,LastPWDReset,LastPWDResetAttempt
$webdata.ServerName = $data.tables.servername
$webdata.SamAccount = $data.tables.samaccount
$webdata.LastPWDReset = $data.tables.LastPWDReset
$webdata.LastPWDResetAttempt = $data.tables.LastPWDResetAttempt

$webdata.LastPWDResetAttempt = "Never"

works. I just can't believe there isn't an easier way, nor do I understand why I can view a list of the data, just to not then be able to set it.

2
  • $data.Tables[0].lastPWDResetAttempt = "None" gives me the same "The property 'lastPWDResetAttempt' cannot be found on this object. Verify that the property exists and can be set." If I try to view it is empty, and of a type "System.DBNull" Commented Mar 29, 2019 at 17:41
  • This seems to be a known issue, the more I look.. That DBNull behavior is strange! Why doesn't it behave as expected? was found on one web site, with a reference to the shutdown Microsoft Connect web site. Several conversations also about checking for NULL - stackoverflow.com/questions/22285149/… but nothing about being able to set the values. Commented Mar 29, 2019 at 17:53

1 Answer 1

0

I think it is because Tables is an array and does not have the property LastPWDResetAttempt.

You can try the following instead:

$data.Tables[0].Rows[0].LastPWDResetAttempt = "None"

Also I think your workaround, though it may contain more lines of code, is actually a better solution though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.