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:
You could also directly embed the environment variable in double quoted string:
Copy-Item "\\server\share\$env:computername.txt" C:\
You need to replace your single quotes with double quotes like this:
$hostname = $env:computername
Copy-Item -Path "\\server\share\$hostname.txt" -Destination 'C:\'
Single quoted strings will not expand variables. You need a double quoted string e.g.:
Copy-Item "\\server\share\$hostname.txt" C:\
And in general, you don't need to quote string arguments to a PowerShell command unless you need variable expansion or there's a space in the string.