I have to get the particular file from one remote desktop to local machine or another server.How to pass a variable in get-content to fetch the file from remote desktop connection?
I store the file path as variable and try to pass it in get-content.
Invoke-Command -Computername $Server -ScriptBlock{get-content -path $file }
Invoke-Command -Computername $Server -ScriptBlock{get-content -path ${file} }
$file="C:\Users\Documents\new DB_connection\\log2.txt"
$Server="servername"
$answer= Invoke-Command -Computername $Server -ScriptBlock{get-content -path $file }
write-output $answer
Cannot bind argument to parameter 'Path' because it is null. + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand