I have the following simple script just prompting a user for a folder name, file name and then 5 names of people. But after I am done, the text is not saved inside the text file. I'd like for the text file to be erased when it is rerun but to have the text in the file until I rerun the script. Help?
$folderName = Read-Host "Please enter the name you want the new folder to have: "
$fileName = Read-Host "Please enter the name you want the new file to have: "
$count = 1
$folder = New-Item C:\Users\Administrator\Desktop -ItemType directory -Name $folderName -force
$file = New-Item C:\Users\Administrator\Desktop\$folderName\$fileName.txt -ItemType file -force
while($count -lt 6){
$name = Read-Host "Please enter the name for person" $count
$name | Add-Content $file
$count++
}
$display = Read-Host "How many names from 1 to 5 would you like to see? "
Write-Host (Get-Content $file -TotalCount $display | Out-String) "`n", "`r`n" | Out-File $file
Write-Hostto write to the pipeline.