• MadAdmin - Thursday, February 22, 2018 8:43 AM

    Sue_H - Thursday, February 22, 2018 7:32 AM

    MadAdmin - Thursday, February 22, 2018 6:54 AM

    using DBATools

    $datatable = Import-Csv C:\temp\customers.csv | Out-DbaDataTable
    Write-DbaDataTable -SqlServer sql2014 -InputObject $datatable -Table mydb.dbo.customers

    Much better than foreach

    Importing data from an existing file is not at all what they are doing though.
    They are getting all services and then for each service, get the service name, status and display name.
    But as the author explained, it's an example for using Invoke-SQLcmd.

    Sue

    Was showing the method, not the solution. Can be applied using any array or dataset.
    So, 

    $var = Get-Service

    Then use that as a parameter in the writedbatable commandlet.
    Simplifies the process into 2 lines.

    Yup..I get that and I use DBATools. Calling the function Write-DbaDataTable from DBATools which does the ForEach. So it's more a matter of using functions in Powershell. The ForEach isn't elimated, it's just used in the function.

    Sue