Category Archives: PowerShell Scripts

Get Windows Firewall State on Local or Remote Machine Utilizing Netsh.exe

Displays the Windows Firewall state for Domain, Private, and Public profiles on local or remote computer.

Use Get-FirewallState to show current Firewall state that is presented on the Windows Firewall with Advanced Security Properties page, with the tabs for Domain, Private, and Public profiles.

Specifies the remote or local computer name.
When using HOSTNAME parameter, Windows PowerShell creates a temporary connection that is used only to run the specified command and is then closed.

Get-FirewallState -HOSTNAME SERVER01

The script will establish remote connection to SERVER01 machine and display the Firewall state for all profiles:




Test-AWSEC2 – Detect if a virtual host is running on Amazon EC2

Amazon EC2 Instances have metadata they can access. They get it by accessing a web server on a link-local address
This PowerShell function will attempt to open http connection to the link-local address, and if successful will confirm that the host is running on Amazon Elastic Compute Cloud (Amazon EC2).

Function run on AWS EC2 virtual machine.
Function run on AWS EC2 virtual machine.



Get File Shares PowerShell Function

Get-FileShares PowerShell function will enumerate all shares (except administrative, but including those that end in a dollar sign ($) on a remote machine and optionally send the output to a CSV file.
The following share properties will be included in the export:
ServerName | ShareName | SharePath | Description

ServerName ShareName SharePath Description
FILESERVER01 \\FILESERVER01\CustomerCare E:\Groups\CustomerCare Customer Care Group Share
FILESERVER01 \\FILESERVER01\Groups_E$ E:\Groups\ Group Share Drive E:
FILESERVER01 \\FILESERVER01\Software$ D:\Software Hidden share for DCA use


Defines the name of the target server
Specifies the path of the exported CSV file


or simply

This will generate a file c:\exports\FILESERVER01_Shares_01-15-2015.csv

Download Link

The Code


Outbound Port Scanner

With Outbound Port Scanner you can determine, which outbound ports aren’t blocked by your firewall.

Outbound Port Scanner with port range 20-30.

This PowerShell tool is extremely helpful when you are behind firewall, and you are running service on a remote machine that you want to connect to it, but you are unable to find out which ports can be accessed and to which port to bind the service.

The Code:
You may want to select a port range (line 2).
The destination host listens on all TCP ports from 1 to 65535.


PowerShell Function: Get Domain/Hostname Geolocation

Get-Geo PowerShell function will resolve the IP address of a domain and return the country name and country code information:

Add this function to a module or save it as ps1 file and dot source it:


WhoIs PowerShell Function

WhoIs PowerShell function will perform a domain name lookup and return information such as domain availability (creation and expiration date),  domain ownership, name servers, etc..

Add this function to a module or save it as ps1 file and dot source it in your profile:


File Report PowerShell Function

Function Get-FileReport
Function Get-FileReport

Get-FileReport function creates detailed file report and exports it into CSV format.


Use this function to export properties for files of certain type (doc, txt, jpg, etc.), and files older than certain days. The report includes the following file properties:
File Name | Full File Path | File Extension | File Size in KB | File Owner | Last Change Date | Computer Name
To use the Get-FileReport functions you can dot source the ps1 file in the PowerShell console:
.  .\Get-FileReport.ps1
or in your profile:

Dot Source Function in Profile
Dot Source PowerShell Function in Profile – Type dot and the full path to the ps1 file.

A comment based help is included. Use Get-Help Get-FileReport -full to retrieve the details bellow.


  • Path
    Specifies the target folder path. Scans the files recursively.
  • Days
    Defines the file age.
  • Ext
    Specifies the file extension.
  • Export
    Exports the results in CSV file. Specifies the folder path for the export file.


Returns the properties of all files under c:\backups.

Returns all files under c:\backups older than 1500 days:

File_Name        : Rmtshare.exe
Full_File_Path   : C:\backups\Rmtshare.exe
File_Extension   : .exe
File_Size_(KB)   : 12.77
File_Owner       : DOMAIN\user
Last_Change_Date : 02/19/1999
Computer_Name    : COMPUTER03

Returns all .txt files under c:\backups older than 150 days:

File_Name        : temp.txt
Full_File_Path   : C:\backups\temp_files\temp.txt
File_Extension   : .txt
File_Size_(KB)   : 0.01
File_Owner       : DOMAIN\user
Last_Change_Date : 02/19/2013
Computer_Name    : COMPUTER03

Exports to CSV all .txt files under c:\backups older than 150 days:

File_Name Full_File_Path File_Extension File_Size_(KB) File_Owner Last_Change_Date Computer_Name
commands.txt C:\backups\commands.txt .txt 0.09 DOMAIN\User 2/21/2013 COMPUTER03
filer_backup.txt C:\backups\filers\filer_backup.txt .txt 0.06 DOMAIN\User 3/12/2013 COMPUTER03
remapping_drive.txt C:\backups\documents\remapping_drive.txt .txt 0.85 DOMAIN\User 9/12/2013 COMPUTER03


You can use (Get-Help Get-FileReport).Examples from the console to retrieve the examples.

The Code:


File Share Quota Manager – Menu Based

File Share Quota Management Tool is a powerful menu based PowerShell script used to remotely control the amount of disk/storage space that a user can utilize on the file server.

File Share Quota Manager
File Share Quota Manager v1.1

Quota manager tool will help system administrators to create, modify, enable or disable quotas on remote file servers.
The user-friendly navigation through the menus and the ability to remotely manage the quotas can save tremendous amount of time spent on manual quota processing during our daily admin tasks.
This tool is extremely helpful for managing file quotas on Windows servers with no PowerShell FSRM module support (which comes with Windows Server 2012).

1. Adds New Quota
-Creates a new quota using standard user share template
2. Shows Quota & Local Drive Information
-Shows common quota parameters & local disk information
-Shows information (free space) for all available local disks (load balancing purposes)
3. Modifies Existing Quota
-Modifies the Quota Limit
-Applies New Standard Templates:
*User Predefined:
*4 GB User Share Hard Quota
*8 GB User Share Hard Quota
*12 GB User Share Hard Quota
*16 GB User Share Hard Quota
*20 GB User Share Hard Quota
*4 GB User Limit with 250 MB Extension
*8 GB User Limit with 250 MB Extension
*12 GB User Limit with 250 MB Extension
*16 GB User Limit with 250 MB Extension
*20 GB User Limit with 250 MB Extension
*Groups Predefined:
*10 GB Group Share Hard Quota
*20 GB Group Share Hard Quota
*30 GB Group Share Hard Quota
*40 GB Group Share Hard Quota
*50 GB Group Share Hard Quota
*10 GB Group Limit with 250 MB Extension
*20 GB Group Limit with 250 MB Extension
*30 GB Group Limit with 250 MB Extension
*40 GB Group Limit with 250 MB Extension
*50 GB Group Limit with 250 MB Extension
-Disables Quota
-Enables Quota

The script leverages the command-line FSRM utility dirquota and requires PSRemoting enabled on the target systems.

Tested on the following platforms:
Windows Server 2003
Windows Server 2008 R2

Download Link:

The code:
In case your preferable way is to access the servers using their virtual names, you need to do few modifications:
-Uncomment line 51. The script will resolve server’s hostname form the DNS. To use FQDN type in the DNS suffix.
-Comment out line 49.

For retrieving the local disks information (lines 75,77) I used filtering to exclude all possible drives that I don’t want to monitor. Those are system drive, Quorum disk, drives that do not support any active shares. You may want to adjust this filtering to fit  with your environment configuration.
To change the standard quota templates use Find/Replace.