donderdag 7 april 2016

Test-NetConnection

To check if a port is open without installing telnet ;-)
 
Test-NetConnection –Computername [computername] –Port [port]
 
 

GPO Back-up Script All

This Script makes a back-up of all GPO’s in your forest incl. child domains.
Make sure you have the folders in place and have enough admin rights! Als check the Environment settings for your own needs.
 
# --------------------------------------------------------------
# Script: Create_Backup_GPO_All_V2.ps1
# Author: Bart Michel
# Date: 06-04-2016
# This script makes a backup of all the GPO's in the domain
# --------------------------------------------------------------
 
#Environment settings
$Enddate = (Get-Date).tostring("ddMMyyyyHHmm")
$Destination = "C:\Scripts\Backup_GPO\GPO_Backup_$Enddate.zip"
$Source = "C:\Scripts\GPO"
$Backupfolder = "C:\Scripts\Backup_GPO\"
$BackupsToKeep = "10"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays(-$BackupsToKeep)
$Extension = "*.zip"
$AllDomains = Get-ADDomain
$TLD = Enter your top level domain
 
# Backup All GPO's in the Domain
Backup-GPO -All -Domain $TLD -Path $Source
foreach($domain in $AllDomains.ChildDomains)
{
    Backup-GPO -All -Domain $domain -Path $Source -ErrorAction SilentlyContinue
}
 
# Create Zip file of all GPO's
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($Source, $Destination)
 
# Clean-up of Temp GPO folder and Backup dir
Get-ChildItem $Backupfolder -Include $Extension -recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item
Remove-Item C:\Scripts\GPO\* -recurse -Force