Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell nothing returned from C#, same code runs in ps prompt with \r\n's removed
    primarykey
    data
    text
    <pre><code>string cmd = " $srv = new-object Microsoft.SqlServer.Management.Smo.Server('" + svr + "')" + Environment.NewLine; cmd += " $srv.Logins | where-object {$_.Name -eq 'DOMAIN\server55' } | select-object 'State'" + Environment.NewLine; </code></pre> <p>That code is added between the PSSnapin &amp; PSSession code then invoked:</p> <pre><code>util&gt;string prep = "$hasSnapin = get-pssnapin | Select { $_.Name.toLower().Trim() = 'sqlservercmdletsnapin100' }" + Environment.NewLine; util&gt;prep += "if ($hasSnapin -eq $null) { Add-Pssnapin SqlServerCmdletSnapin100 }" + Environment.NewLine; util&gt;cmd = prep; util&gt;cmd = "$pssessSql = New-PSSession -ComputerName " + svr + Environment.NewLine; util&gt;cmd += " Invoke-Command -session $pssessSql -ScriptBlock {" + Environment.NewLine; util&gt;cmd += " " + " sqlps -nologo -noprofile -command {" + Environment.NewLine; util&gt;cmd += " " + command + " }" + Environment.NewLine; util&gt;cmd += " }" + Environment.NewLine; util&gt;cmd += " Remove-PSSession -Session $pssessSql" + Environment.NewLine; util&gt;cmd += " exit"; util&gt;try { util&gt;IList&lt;System.Management.Automation.PSObject&gt; results = pipeline.Invoke(); util&gt;runspace.Close(); util&gt;return results; util&gt;} </code></pre> <p>If I capture the script going to the Invoke it works by replacing "\r\n" with a newline, why wouldn't it work in C#, I have a other scripts working from the C# so may be missing something obvious, here's the captured code that runs from a ps prompt:</p> <pre><code>$hasSnapin = get-pssnapin | Select { $_.Name.toLower().Trim() = 'sqlservercmdletsnapin100' } if ($hasSnapin -eq $null) { Add-Pssnapin SqlServerCmdletSnapin100 } $pssessSql = New-PSSession -ComputerName Server54 Invoke-Command -session $pssessSql -ScriptBlock { sqlps -nologo -noprofile -command { $srv = new-object Microsoft.SqlServer.Management.Smo.Server('Server54') $srv.Logins | where-object {$_.Name -like 'DOMAIN\Server55$' } | select-object 'State' } } Remove-PSSession -Session $pssessSql exit </code></pre> <p>Thanks for any clues, I've had trouble with nested quotes but able to get most of those so this is I think from the \r\n's in the code but not sure how to find that out, I can't get the results to return from the app but the whole script does fine via a ps prompt.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload