Tuesday, 5 May 2020

Powershell Output (“echo”) a variable to a text file

https://stackoverflow.com/questions/19122755/output-echo-a-variable-to-a-text-file


After some trial and error, I found that
$computername = $env:computername
works to get a computer name, but sending $computername to a file via Add-Content doesn't work.
I also tried $computername.Value.
Instead, if I use
$computername = get-content env:computername
I can send it to a text file using
$computername | Out-File $file

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive