Powershell script to append a file and to create the file/folder if not exist
Thanks Jeffrey Snover for the comment and tip for my previous script. It is really short and sweet!
Here is a script to append a log file and to create the folder and file if they don't exist.
$a = "C:\Temp1"
$b = "\Rebootlog.txt"
$c = $a + $b
$d = get-date
If(Test-Path $a)
{
If (Test-Path $c)
{Add-content $c "SMS will Reboot Server 5 Minutes After $d"}
Else
{new-item $c -type file
Add-content $c "SMS will Reboot Server 5 Minutes After $d"
clear-host}
}
Else
{New-Item $a -Type Directory
new-item $c -type file
Add-content $c "SMS will Reboot Server 5 Minutes After $d"
clear-host}