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

586 Views Asked by At

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

1

There are 1 best solutions below

0
Mathias R. Jessen On BEST ANSWER

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

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