Solved

error on cmd split when dbname contains _

Posted on 2013-05-28
4
271 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
  • 2
  • 2
4 Comments
 
LVL 39

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 39

Accepted Solution

by:
footech earned 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now