How to dump firewall rules into file with powershell

Hi everybody,

again a short note for my self to not search again in my offline notes. 😉

How to dump Firewall rules with Powershell 3.0 and newer in a file “oneliner”.

Inbound rules:

 

Outbound rules:

 

#PS Script that filters AD Computers and moves it to specified OU

I wrote this script to filter my Active Directory Domain for Computers beginning with “SMB-” and move them to an Organizational Unit (OU) with the name “SMB-OU”.

You can use the script but you have to change the OU, Computer filter and Domain so that it matches your search and domain criteria.

I use the Outfile command to create a logfile from the movement for documentation.

Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Out-File c:\move_resultates_before.txt #writes status before any computer will moved in output file
Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Move-ADObject -TargetPath “OU=SMB-OU, DC=Datacenter-Flo, DC=de” #and moves the computer to OU named SMB-OU in domain Datacenter-Flo.de (you have to change to your domain)
Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Out-File c:\move_resultates_aftwe.txt #writes status after the computers were moved in output file
 

At the moment there is no security and other filters included. Only quick and dirty but it’s working.

Mounting .vhd during OS boot via script

Hi Community,

in this blog I will show you how to mount a .VHD file during boot.

1. create a new .txt and type in:

select vdisk file=<filepath to vhd><vhd name>.vhd #example select vdisk file=d:\Brighteyes_Win7_installation.vhd

attach vdisk

2. create a new .bat file

diskpart -s “<filepath to .txt file>” #example “d:\scriptsautomount_data.txt”

3. copy both files on the same harddrive where the your .vhd are located. If you have .vhd files at different positions, copy them in your windows rootdirectory (subfolders are also ok)

4. now you have two options to run the script

Option 1: easiest but worstest way

a. create a link to the batchfile in your autostart folder

Option 2: good middleway

a. click right on the computer icon and select manage

b. Open the computer management and go on Task Scheduler

c. click on create task

d. under general please select:

Name: What ever you think

Discription: Mount VHD file xyz

select -> Run whether user is logged on or not: 

select -> Run with highest priviliges

select -> Configured for Windows 7 and Windows 2008 R2 

e. go on Triggers and klick new

f. select Trigger at startup and klick ok 

g. go on conditions and remove all marks from the checkboxes

h. go on settings and change following options

select -> allow task to be run on demand

select -> Run task as soon as possible after a scheduled task is missed

select -> after the task failed, restart every: 1 minute

select -> Attempt to restart up to: 3 times

select -> stop the task if it runs longer than: 1 houre

select -> ih the running task does not end when requested force it to stop

i. klick ok 

j. restart your OS and check if the HD is mounted

It is also possible to mount VHDs with local or group policy’s. I will explain this in one of my next blogposts.