kdeutsch
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.sqlC ommand($Sq l, $conn)
$rdr = $cmd.ExecuteReader()
While($rdr.read())
{
$UserId =($rdr["intUserId"].tostri ng())
$Sam =($rdr["strLogon"].tostrin g())
$Edipi =($rdr["strEdipi"].tostrin g())
}
$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
$Sql = "Select intUserId, strLogon, strEDIPI from iMAC_Users where bitUpdate = 1"
$cmd = New-Object system.data.sqlClient.sqlC
$rdr = $cmd.ExecuteReader()
While($rdr.read())
{
$UserId =($rdr["intUserId"].tostri
$Sam =($rdr["strLogon"].tostrin
$Edipi =($rdr["strEdipi"].tostrin
}
$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
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.
ASKER
Hi,
Nope in the sql db its a Varchar(10), never use nvarchar at all.
Nope in the sql db its a Varchar(10), never use nvarchar at all.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok wow,
need to go home and start gaming.
Thanks
need to go home and start gaming.
Thanks
ASKER
thanks