Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

error on cmd split when dbname contains _

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

636 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