One more thing, Invoke-SqlCmd will not by default tell you how many row(s) affected like sqlcmd does, so this is how you can get that info.
IduRows is for any inserts, deletes, or updates; SelectRows is for any selects.
# AdHocQuery.ps1
# must have run AccessToken.ps1 first
Invoke-Sqlcmd -ServerInstance YOURSERVER -Database YOURDATABASE `
-AccessToken $access_token -ConnectionTimeout 10 `
-StatisticsVariable "sqlcmd_statistics_dictionary" `
-ApplicationName "Invoke-Sqlcmd" -Query $args[0]
$sqlcmd_statistics_object = ($sqlcmd_statistics_dictionary `
| %{New-Object PSObject -Property $_})
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
IduCount, IduRows, SelectCount, SelectRows, SumResultSets, `
Transactions, BuffersSent, BytesSent, BuffersReceived, BytesReceived
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
ConnectionTime, ExecutionTime, NetworkServerTime, ServerRoundtrips, `
CursorOpens, PreparedExecs, Prepares, UnpreparedExecs
# ReadSqlFile.ps1
# must have run AccessToken.ps1 first
Invoke-Sqlcmd -ServerInstance YOURSERVER -Database YOURDATABASE `
-AccessToken $access_token -ConnectionTimeout 10 `
-StatisticsVariable "sqlcmd_statistics_dictionary" `
-ApplicationName "Invoke-Sqlcmd" -InputFile ("YOURROOTFOLDER/{0}" -f $args[0])
$sqlcmd_statistics_object = ($sqlcmd_statistics_dictionary `
| %{New-Object PSObject -Property $_})
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
IduCount, IduRows, SelectCount, SelectRows, SumResultSets, `
Transactions, BuffersSent, BytesSent, BuffersReceived, BytesReceived
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
ConnectionTime, ExecutionTime, NetworkServerTime, ServerRoundtrips, `
CursorOpens, PreparedExecs, Prepares, UnpreparedExecs