Add IP address with the input

Hello everybody,

I will need your help, I am new with the powershell cmd.
I would like to create a powershell script, which can create a file, add different stuff in this file, and modify one line, to add the ip address.

For exemple this my script so far :
#ask for the IP address to add in the text files
$input = Read-Host Prompt “What is the IP address ?”
#create the directory and file
New-Item -Path ‘C:\test’ -ItemType Directory
New-Item -Path ‘C:\test\file1’ -ItemType File
#add content the file
Add-Content -Path ‘C:\test\file1’ -Value ‘{
“status”: “success”,
“response”: {
“Ip address”: “$input”,
}’ -Force

I would love to replace “$input” in the file with the IP address.
I don’t know how to do it.
I will appreciate your help.

Thank you !

Welcome to the forum. :wave:t4:

Please, when you post code or sample data or console output you should format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance

Instead of creating the file first and chaging it later I’d prefer using a here-string as template and input the received IP address before writing the file to the disk.

Something like this:

$IPAddress = Read-Host Prompt 'What is the IP address ?'
$TextTemplate = 
"status": "success",
"response": {
"Ip address": "$($IPAddress)",

New-Item -Path 'C:\test' -ItemType Directory 
$TextTemplate | 
    Out-File -FilePath 'C:\test\file1.txt'

Oh sorry for that ! I will use the preforrmatted text button next time.

This is exactly what I needed, it works !
Thank you so much !