Powershell automation of SCCM reports through Posh tool . RRS feed

  • Question

  • Hi all,

    i am looking for the solution to inbuilt the credentials inside the PoSH tool which i have created for SCCM reports. But the big question is i am not able to inbuilt the credentials in the script. i tried multiple ways to get this done but still no luck . 

    one of the way which i have used is below.

    $Global:SCCMSQLSERVER = "servername" $Global:DBNAME = "dBname" Try { $SQLConnection = New-Object System.Data.SQLClient.SQLConnection $SQLConnection.ConnectionString ="server=$SCCMSQLSERVER;database=$DBNAME;Integrated Security=True;User id = domain\username; Password=userpassword" $SQLConnection.Open() } Catch { [System.Windows.Forms.MessageBox]::Show("Failed to connect SQL Server:") } #endregion SCCMSQLCONNECTION

    Friday, December 13, 2019 11:40 AM

All replies

  • Omit the user and password from the connection string. When you specify integrated security true, the current Windows credentials are used to connect to the database.

    Use RUNAS if you need to run the script under a different security context.

    Dan Guzman, Data Platform MVP,

    Friday, December 13, 2019 12:05 PM
  • if i will make the changes in integrated security = False then i believe the string will only accept users which are created in SQL only . but i wanted to login with AD authentication. my purpose is to create a Posh which anyone can run but the sql will connect only specified credentials in the script . 

    and in the other scenario "Runas" i have to call the script by the path. which i do't want to prefer .

    Friday, December 20, 2019 10:08 AM