Avatar of kdeutsch
kdeutsch
Flag for United States of America asked on

Powershell putting spaces bewteen string on database pull

I am pulling some information from a database to first queury AD and its putting spaces in a string that I am pulling.  In the Db I store a number as a string becuase to leading or ending zeros and then pull as a string and format as a string but my poweshell script is putting spaces in between teh numbers.

$Sql = "Select intUserId, strLogon, strEDIPI from iMAC_Users where bitUpdate = 1"
$cmd = New-Object system.data.sqlClient.sqlCommand($Sql, $conn)
$rdr = $cmd.ExecuteReader()


While($rdr.read())
    {
        $UserId =($rdr["intUserId"].tostring())
        $Sam =($rdr["strLogon"].tostring())
        $Edipi =($rdr["strEdipi"].tostring())
    }
$conn.close()


Write-Host $UserId
Write-Host $Sam
Write-host @Edipi

the id and same name are fin but the @Edipi should come out as a 10 number field such as
1234567895

but it comes out as this
1 2 3 4 5 6  7 8 9 5
ASP.NETPowershell

Avatar of undefined
Last Comment
kdeutsch

8/22/2022 - Mon
Qlemo

Did you by any chance define the field as being nvarchar? The output looks like Unicode encoded and displayed as char array, with each second byte being zero.
kdeutsch

ASKER
Hi,
Nope in the sql db its a Varchar(10), never use nvarchar at all.
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
kdeutsch

ASKER
ok wow,
need to go home and start gaming.
Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
kdeutsch

ASKER
thanks