[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

error on cmd split when dbname contains _

Posted on 2013-05-28
4
Medium Priority
?
282 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 41

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 41

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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

872 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