Hi @ANKIT SINGH ,
I played around with the script. Please check if this is working for you. Be aware to start services you need to have administrator privileges on the computer.
CSV file (test2.csv):
wlidsvc,action
AxInstSV,start
AppReadiness,start
Script:
function FuncCheckService {
param($wlidsvc,
$action
)
$service = Get-Service -Name $wlidsvc -ErrorAction SilentlyContinue
if ($service) {
if ((($service).Status -ne "Running" -and ($service).StartType -ne "Disabled") -and ($action -eq "start")) {
Start-Service $wlidsvc
Write-Host "Starting $wlidsvc service `r`n ---------------------- "
Write-Host -ForegroundColor Green " $wlidsvc service is now started"
}
if ($service.Status -eq "running") {
Write-Host "$wlidsvc service is already started" -ForegroundColor Yellow
}
if ($action -ne "start" -and (($service).Status -ne "running")) {
Write-Host "$wlidsvc service does not have action start set" -ForegroundColor Magenta
}
}
else {
Write-Host "$wlidsvc service not found" -ForegroundColor Red
}
}
$lines = Import-Csv -Path C:\Junk\test2.csv -Delimiter ","
foreach ($line in $lines) {
FuncCheckService -wlidsvc $line.wlidsvc -action $line.action
}
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten