Posted By BikeBoy on 09 Feb 2010 10:34 AM
another starnge thing I am expiencing is it looks like 2 shells are not the same: 32bit in C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe doesn't understand TrimEnd method
I get [System.Object[]] doesn't contain a method named 'TrimEnd'. error
64bit has no problem with that
As Marco pointed out you have a command that is returning a single string value on some cases and returning an array of strings in others. If you can find that command you can enclose it with
@()
to always get an array. Then you can iterate over the array and call the TrimEnd() method on the elements in the array.
My guess is that the Sqlcmd command returned a single string during testing and is now returning multiple strings. If you're goal is to process each string separately then you should force an array out of the command:
[string[]]$P= @(Sqlcmd -E -d"MyDB" -S "$Servername" -h-1 -Q "set nocount on; select value from dbo.BackupDefaults where name = 'DataPath';")
$Path = @($p | where {$_} | foreach { $_.TrimEnd() })
This will give you an array in $Path. If you are truly expecting only one result then you need to determine why you are getting multiple lines of output from Sqlcmd.