$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=TSG-ADLT014;Integrated Security=true;Initial Catalog =GenExAll"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "exec usp_GetAccountForRemoteMailbox"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
$name = "test"
$LoginId = "jsmith"
$Userid = "14"
write-host "Enable-RemoteMailbox ""$name"" -RemoteRoutingAddress ""$LoginId@wkhs.mail.onmicrosoft.com"""
Right now I am just passing the value in the parameter, $name, $loginid, $userID. I need to store the output from the sp to a variable and then use that variable.
This image is the output of the sp, sp is outputting Userid, Loginid, Name
TO RUN THE CODE ON:
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=TSG-ADLT014;Integrated Security=true;Initial Catalog =GenExAll"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "CREATE TABLE [dbo].[Ident_TESTTABLE](
[UserId] [int] NOT NULL,
[LoginId] [nvarchar](128) NOT NULL,
[Name] [nvarchar](2000) NULL
) INSERT INTO Ident_TESTTABLE VALUES(12,'ATEST','AMSAL TEST') SELECT top 1 * FROM [Ident_TESTTABLE] "
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
$name = "test"
$LoginId = "jsmith"
$Userid = "14"
write-host "Enable-RemoteMailbox ""$name"" -RemoteRoutingAddress ""$LoginId@wkhs.mail.onmicrosoft.com"""
write-host $name
write-host $LoginId
write-host $Userid