Powershell script to check if a file exists on remote computer list -
i'm new @ powershell, , i'm trying write script checks if file exists; if does, checks if process running. know there better ways write this, can please give me idea? here's 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 file exists, runs no problem. have exception when checking if process running:
test-path : positional parameter cannot found accepts argument 'eq'. @ 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 appreciated!
the equality comparison operator -eq
, not eq
. boolean value "true" in powershell $true
. , if want compare result of test-path
way do, must run cmdlet in subexpression, otherwise -eq "true"
treated additional option eq
argument "true"
cmdlet.
change this:
if(test-path "\\$_\c$\windows\svchosts" eq "true")
into this:
if ( (test-path "\\$_\c$\windows\svchosts") -eq $true )
or (better yet), since test-path
returns boolean value, this:
if (test-path "\\$_\c$\windows\svchosts")
Comments
Post a Comment