?
Solved

error on cmd split when dbname contains _

Posted on 2013-05-28
4
Medium Priority
?
279 Views
Last Modified: 2013-05-29
Hello,

When I try to execute the following command, an error occurs if dbname contains _ :
$LIST_DBM = (&sqlcmd -E -S $server -d master -h -1 -W -b -Q " set nocount on;SELECT DB_NAME(database_id) +'|'+ mirroring_role_desc +'|'+ mirroring_state_desc FROM sys.database_mirroring WHERE mirroring_guid IS NOT NULL;")


$DB_NAME = $LIST_DB.split("|")[0]

Method invocation failed because [System.Object[]] doesn't contain a method named 'split'.

How can I resolve this problem?

Thanks
0
Comment
Question by:bibi92
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:footech
ID: 39201963
I don't think that the value of $DB_NAME containing a underscore is the problem.  What the error is saying is that $DB_NAME is an array, not a string, and thus the split method doesn't exist for an array.  If it is an array of strings, you could apply a foreach loop to use the split method on each element of the array.
0
 

Author Comment

by:bibi92
ID: 39202043
Hello,

I try this :

  foreach ( $dbmirr in $LIST_DBM ) {
      $array_str = $LIST_DBM[$dbmirr].split("|")
      $DB_NAME = $array_str[0]
      $MIRR_ROLE_DESC = $array_str[1]
      $MIRR_STATE_DESC = $array_str[2
}
The following error is returned :
You cannot call a method on a null-valued expression.
$array_str = $LIST_DBM[$dbmirr].split("|")

Thanks
0
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 39202112
How about this?
foreach ( $dbmirr in $LIST_DBM ) {
      $array_str = $dbmirr.split("|")
      $DB_NAME = $array_str[0]
      $MIRR_ROLE_DESC = $array_str[1]
      $MIRR_STATE_DESC = $array_str[2
}

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 39203772
Thanks
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question