Having what seems to be a basic problem in Powershell. I am doing a simple copy-item script from a UNC share to the local C:\ drive. Here is my code:
$hostname = $env:computername
Copy-Item -Path '\\server\share\$hostname.txt' -Destination 'C:\'
I can’t figure out the syntax to have it retrieve the text file that matches the name of the hostname using the variable. If I put in a statically named .txt file that code works.
What do I have to put around that variable for it to work?
You need to replace your single quotes with double quotes like this: