KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm confused about the difference between echo and Write-Host in PowerShell. I have two files, POC.ps1 & validatePath.ps1 . These files are on my local machine, and I'm running them on a remote machine using Invoke-Command . I am using PowerShell v3.0. To execute both of these scripts I use the command: .\POC.ps1 -filename C:\Users -user Blaine Here are the two files: POC.ps1: param($filename, $user) echo $filename echo "This" echo $user $responseObject = Invoke-Command testcomputer -FilePath .\validatePath.ps1 -ArgumentList($filename, $user) -AsJob while($responseObject.State -ne "Completed") { } $result = Receive-Job -Id $responseObject.Id -Keep echo $result Here is where things get weird... validatePath.ps1: Param([string] $filename, [string] $user) function ValidatePath( $filename, $user, $fileType = "container" ) { Write-Host "This is the file name: $filename" Write-Host "This is user: $user" <--- Notice I'm using Write-Host here $fileExist = $null if( -not (test-path $filename -PathType $fileType) ) { throw "$user, the path $filename does not exist!" } else { Write-Host "This is the second part" echo $filename found! } Write-Host "This is the third part" return $fileExist } try { ValidatePath($filename, $user) } catch { $e = $_.Exception echo $e } When I run the above script, this is the output: C:\Users This Blaine This is the file name: C:\Users Blaine This is user: <--- Notice where this line is? This is the second part This is the third part C:\Users Blaine found! But if I change the validatePath.ps1 to this: Param([string] $filename, [string] $user) function ValidatePath( $filename, $user
Tags (comma-separated)
Save Edits
Cancel