I'd like to run a Power shell script on start up that will query the local hostname and rename a local file by inserting the result.
For example, get hostname using something like:
$(Get-WmiObject Win32_Computersystem).name
..and insert the result into a file named and located as below,
C:\output\file-from-`Insert hostname`.txt
Its using the result of the Get-WmiObject
to rename the existing file that I'm stuck with.
Any help would be great.
:-)
CodePudding user response:
This should do the trick.
Rename-Item -Path "C:\output\file-from-Insert hostname.txt" -NewName "C:\output\file-from-$($env:COMPUTERNAME).txt"