question

AbhishekReddy-5190 avatar image
0 Votes"
AbhishekReddy-5190 asked AbhishekReddy-5190 commented

Extract only perticular data from excel coulmn by using powershell

Requirement is to fetch only name of service by cutting down before and after period, AAA.BBB.CCC is the service name which is writing to excel so while importing that excel we need to have trimmed it to display only BBB.

Please help here

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered AbhishekReddy-5190 commented

Try changing that "select" cmdlet to:

 $res | Select-Object @{n='ServiceName';e={($_.ServiceName -split "\.")[1]}}, Status, MachineName


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot for your swift response sir, it worked exactly how I wanted it to be.
Thank you for the help !

0 Votes 0 ·
StoyanChalakov avatar image
0 Votes"
StoyanChalakov answered AbhishekReddy-5190 commented

Hey,

can you please post the script you have written? Please explain what is not working, what the challenges are?

Thanks in advnace!

Regards,
Stoyan

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Stoyan,
Please see below
'You chose option #6'
$services = Get-Content -Path "C:\SoftWares\Server\Services\Pitsburg.txt"
$machines = Get-Content -Path "C:\SoftWares\Server\Servers\Pitsburg.txt"
foreach ($computer in $machines)
{
Write-host "Services are going to be detailed on $computer" -b "green" -foregroundcolor "Black"
$res += foreach ($service in $services)
{
Get-Service -ComputerName $computer -Name $service
}
}
$res |select ServiceName,Status,MachineName | Export-Csv -NoTypeInformation -Encoding UTF8 -Path "C:\SoftWares\Server\Pitsburg Services.csv"
$R = Import-Csv -Path "C:\SoftWares\Server\Pitsburg Services.csv" | sort -Property "Status"
$R | Format-Table
break

This is the code, it is working fine but I wanted to shorten the service Name, as of now it writes in the excel and imports AAA.BBBB.CCCC but I wanted only BBBB.

Kindly help

0 Votes 0 ·