Search code examples
powershellnew-item

How to use New-Item with $Version to create a text file


I have pulled some information from the registry using Get-ItemPropertyValue and would like to use this to create a text file with that value.

$Version = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'DisplayVersion')

Example output - 21H1

Trying to use New-Item with $Version output to create a text file, 21H1.txt


Solution

  • Use your variable in an expandable string, and pass the resulting string value to New-Item's -Name parameter

    New-Item -Name "${Version}.txt"