Link to home
Start Free TrialLog in
Avatar of Dee M
Dee M

asked on

ps csv format inquiry

Hi,

Can you help, I have a powershell script that will query a SQL file given the list of servers if the Events exist or not or if it is running or stopped. I already have the code but not getting what my expected format in csv. See the code below:

$QueryPath=”C:\DBA\EE\ExtnddEvent.sql”
$OutputFile=”C:\DBA\EE\Output.csv”

$ExecuteQuery= Get-Content -path $QueryPath | out-string

“Results — > `r`n`r`n” > $OutputFile

FOREACH($server in GC “CC:\DBA\EE\Server_List.txt”)
{
$server 
“——————————-” >> $OutputFile
$server >> $OutputFile
“——————————-” >> $OutputFile
invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 60000 | ft -autosize | out-string -width 4096 >> $OutputFile
}

Open in new window


Actual Result:
User generated image
Preferred Result:
User generated image
Note: Can you also remove in the output the words Result(Results — > ) and the ServerName on the Actual Result since it is already showing the ServerName(Server1\Instance1)
result.PNG
result_expected.PNG
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dee M
Dee M

ASKER

Thanks