I create a batch file with:
%computername% > %computername%.txt
It works great and creates the text file with computer name. But how to create the same in PowerShell?
Different codes do not work, or my ideas are wrong. Only the computer name is in the text file but I wish to use the computer name for my text file if I don't know the name.
I tried:
Hostname >> .txt
But this writes the hostname in a file named .txt.
Next try:
$env:computername > $env:computername.txt
But this does nothing.
I don't know what I can do?