Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Trim data from CSV file after a Special Character

$
0
0

Hi Everyone,

I am trying to read data from csv file i am using Import-csv cmdlet. this csv file has SQL Server data with instance names as below

Instance

Test

Test1\002

Test2

Test3\001

I want to trim the instance name and read only server name from the csv file. Looking for help for achieving this.

I am preparing a report with the details of the SQL Server services:

 

my script is as foillows

$InputFile = Import-Csv "C:\Test\SQLInstance.csv"

foreach($Servers in $Inputfile)
{
Write-Host "ServerName:" $Servers.instance
Get-WmiObject win32_service  -ComputerName $Servers.instance  | Select Name, Startmode, State  | Where-Object `
{$_.name -like "*SQL*" -and $_.Startmode -match "Auto" -and $_.state -match "Stopped"} | FT -AutoSize
}

 

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles