March 26, 2015 at 2:46 pm
Hi
Need the output of the results to a comma / semi colon / pipe delimited format.
Function RunningSQLServices
{
[CmdletBinding()]
Param
(
[Parameter(Position=0,Mandatory=$true)][string]$filepath #Enter filename containing server names with single quotes
, [Parameter(Position=1,Mandatory=$true)][string]$outfile #Enter path with single quotes (The file will be recreated if you use the same output file.)
)
Process
{
$result=@()
ForEach ($objitem in get-content $filepath) {
$result += $objitem |out-file $outfile
$result += get-service -ComputerName $objitem -displayname *SQL*| Where-Object {$_.status -eq "Running"}| Select-Object Machinename, Status,Name,DisplayName | format-table -auto -wrap -force
}
#$result | export-csv $outfile -Delimiter "|" -NoTypeInformation
$result | out-file $outfile
#$result | Export-Csv -Path 'C:\service_status1.txt' -Delimiter ';' –notype
#$result |export-csv -delimiter "$" -path $outfile
}
}
## This is the way to trying to convert. But no luck.
$path = 'C:\service_status1.txt'
$outPath = $path -replace ".txt",".csv"
Get-Content -path $path |
ForEach-Object {$_ -replace "\s",";" } |
Out-File -filepath $outPath
Thanks.
March 27, 2015 at 1:29 am
So what is going wrong? How does that differ from what you are expecting?
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply