I am new to Powershell and I am trying to write a script that checks if a file exists; if he does, he checks to see if the process is running. I know there are much better ways to write this, but can someone please give me an idea? Here is 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, works without problems. But I have an exception, 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!
powershell
Bianca borges
source share