As for this,
"$cat ExampleFile.txt"
$cat or "$cat" specified this way is a variable.
"$cat D:\temp\TestFile.txt"
# Results
<#
"$cat D:\temp\TestFile.txt"
The variable '$cat' cannot be retrieved because it has not been set.
At line:1 char:2
+ "$cat D:\temp\TestFile.txt"
+ ~~~~
+ CategoryInfo : InvalidOperation: (cat:String) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
#>
PS will evaluate that to whatever is the value/data in the $cat
variable, not run the cat command.
See the available info on PowerShell variable expansion.
https://devblogs.microsoft.com/powershell/variable-expansion-in-strings-and-here-strings/
As noted cat
is an alias for Get-Content
, and it must be used that way.
For the command to work, you must do it this way.
cat ExampleFile'D:\temp\TestFile.txttxt'
# Results
<#
1 21/05/20
2 21/05/20
3 21/05/20
4 21/05/20
5 21/05/20
6 21/05/20
7 21/05/20
8 21/05/20
#>
Unless you did this...
$cat = cat
... somewhere else in your code. Meaning you assigned a command to a variable name. Which, especially for a single comment is not really prudent.
If you tried that in this use case, it would still fail.
$cat = cat
"$cat D:\temp\TestFile.txt"
# Results
<#
$cat = cat
"$cat D:\temp\TestFile.txt"
cmdlet Get-Content at command pipeline position 1
Supply values for the following parameters:
Path[0]:
#>
Lastly for any command to be discoverable, it must be in your system and PS paths.
See also PS command precedence
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-7.3