In Windows 7 you an create VPN connections for PPTP, L2TP or SSTP. To delete a connection you can not just right click and press delete. But it’s still very simple, but a lot of people can’t find where you can remove VPN connections, because it is a kind of hidden
.
Tag Archives: Remove
Powershell: How to export Windows Eventlogs with Powershell

This is a little dirty Windows Powershell script which exports or backups Windows Eventlogs. The script creates a .evt file which can be used with the Windows Eventlog Viewer.
# Config
$logFileName = "Application" # Add Name of the Logfile (System, Application, etc)
$path = "C:\temp\" # Add Path, needs to end with a backsplash
# do not edit
$exportFileName = $logFileName + (get-date -f yyyyMMdd) + ".evt"
$logFile = Get-WmiObject Win32_NTEventlogFile | Where-Object {$_.logfilename -eq $logFileName}
$logFile.backupeventlog($path + $exportFileName)
And with the next code it cleans up older exported Eventlogs.
# Deletes all .evt logfiles in $path
# Be careful, this script removes all files with the extension .evt not just the selfcreated logfiles
$Daysback = "-7"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path | Where-Object { ($_.LastWriteTime -lt $DatetoDelete) -and ($_.Extension -eq ".evt") } | Remove-Item
UPDATE: If you wanna clean the Eventlog after the export you can do that by using the Clear-Eventlog cmdlet. (Thanks to Michel from server-talk.eu)
Clear-Eventlog -LogName $logFileName
And here the whole “script”
# Config
$logFileName = "Application" # Add Name of the Logfile (System, Application, etc)
$path = "C:\temp\" # Add Path, needs to end with a backsplash
# do not edit
$exportFileName = $logFileName + (get-date -f yyyyMMdd) + ".evt"
$logFile = Get-WmiObject Win32_NTEventlogFile | Where-Object {$_.logfilename -eq $logFileName}
$logFile.backupeventlog($path + $exportFileName)
# Deletes all .evt logfiles in $path
# Be careful, this script removes all files with the extension .evt not just the selfcreated logfiles
$Daysback = "-7"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path | Where-Object { ($_.LastWriteTime -lt $DatetoDelete) -and ($_.Extension -eq ".evt") } | Remove-Item
Clear-Eventlog -LogName $logFileName
Powershell: Working with XML part 2
After my first post (Powershell: Parsing XML part 1) about working with XML and Powershell, I have create this second post which describes how to create a XML file, Add content to the XML file, remove content from the XML file and save the XML objects as a file.
While I was writing a script which communicates with a webserver, I realized that I need some error handling if the server can not anwser a request from my script. For example if the webserver is down or has to much load.
I created a little retry part (Powershell: Simple retry logic) which retries several times. But if the Server is down for several hours or days your script hangs in a retry loop. Obviously this cant be the solution. After a little bit of thinking a decided to write the data, which I was trying to send, down in a XML file. And the next time the script runs it reads the XML file and tries to send the data again.
Thats the story behind my idea for saving data in a XML file.
Creating a XML object
[XML]$FruitList = "<Box> <Fruit> <Name>Banana</Name> <Color>yellow</Color> </Fruit> </Box>"
Save a XML object as a XML file
$FruitList.Save("./myfruitlist.xml")
XML:
<Box> <Fruit> <Name>Banana</Name> <Color>yellow</Color> </Fruit> </Box>
Open a saved XML file
[xml]$FruitList = Get-Content ./myfruitlist.xml
Add data to XML object and save it in a XML file
# Copy Object from Banana
[Object]$CopyFruit = FruitList.Box.Fruit | Where-Object {$_.Name -eq "Banana"}
$NewFruit = $CopyFruit.Clone()
# Add Fruit to new Object
$NewFruit.Name = "Apple"
$NewFruit.Color = "green"
# Add Fruit to XML Object
$FruitList.Box.AppendChild($NewFruit)
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
XML:
<Box> <Fruit> <Name>Banana</Name> <Color>yellow</Color> </Fruit> <Fruit> <Name>Apple</Name> <Color>green</Color> </Fruit> </Box>
Change data from XML Object and save it as XML file
# Change Apple Color
$FruitList.Box.Fruit | Where-Object {$_.Name -eq "Apple"} | ForEach-Object { $_.Color = "red" }
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
XML:
<Box> <Fruit> <Name>Banana</Name> <Color>yellow</Color> </Fruit> <Fruit> <Name>Apple</Name> <Color>red</Color> </Fruit> </Box>
Remove data from XML Object and save it as XML file
# Remove Banana from Object
$RemoveFruit = $FruitList.Box.Fruit | Where-Object {$_.Name -eq "Banana"}
$FruitList.Box.RemoveChild($RemoveFruit)
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
XML:
<Box> <Fruit> <Name>Apple</Name> <Color>green</Color> </Fruit> </Box>
