I'm new at Powershell, and I'm trying to write a script that checks if a file exists; if it does, it checks if a process is running. I know there are much better ways to write this, but can anyone please give me an idea? Here's what I have:
Get-Content C:\temp\SvcHosts\MaquinasEstag.txt | `
Select-Object @{Name='ComputerName';Expression={$_}},@{Name='SvcHosts Installed';Expression={ Test-Path "\\$_\c$\Windows\svchosts"}}
if(Test-Path "\\$_\c$\Windows\svchosts" eq "True")
{
Get-Content C:\temp\SvcHosts\MaquinasEstag.txt | `
Select-Object @{Name='ComputerName';Expression={$_}},@{Name='SvcHosts Running';Expression={ Get-Process svchosts}}
}
The first part (check if the file exists, runs with no problem. But I have an exception when checking if the process is running:
Test-Path : A positional parameter cannot be found that accepts argument 'eq'.
At C:\temp\SvcHosts\TestPath Remote Computer.ps1:4 char:7
+ if(Test-Path "\\$_\c$\Windows\svchosts" eq "True")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Path], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.TestPathCommand
Any help would be appreciated!