Creating and automatically deleting a file using PowerShell RRS feed

  • Question

  • I am fairly new to PowerShell and trying to learn.

    I am sriting a test script that creates a folder, then a TXT file under that folder, enters data into the TXT file, then waits 30 seconds, then deletes the folder. I use the -recurse at the end of the script to automatically remove the folder without asking to remove the folder but it waits for me to hit the enter key to perform the action. Everything works except the last action. Powershell puts the command on the line but I have to hit the enter key to finish the action.

    I am testing a way to create a script to run with no user intervention including deleting items or entering additional data. How do I get my script to finish with no user intervention? Any help is greatly appreciated.

    new-item -path c:\users\gsmith\documents -name test -itemtype directory
    new-item -path c:\users\gsmith\documents\test -name test.txt -itemtype file
    add-content -path c:\users\gsmith\documents\test\test.txt -value "Get Bent"
    add-content -path c:\users\gsmith\documents\test\test.txt -value "Jump on It"
    add-content -path c:\users\gsmith\documents\test\test.txt -value "What's Next"
    wait-event -timeout 30
    remove-item -path c:\users\gsmith\documents\test -recurse

    • Moved by Just KarlModerator Thursday, December 28, 2017 3:08 PM Looking for the correct forum
    Wednesday, December 20, 2017 11:17 PM


All replies