Showing posts with label CSV. Show all posts
Showing posts with label CSV. Show all posts

2014/09/01

PowerShell - Sum similar entries from multiple CSV files

One of my script is scheduled to download everyday the proxy logs files from multiple proxies (Approx 1>2GB per file) of the previous day. The second step is to parse each of them and get the top 200 domain names within a specific environment. Finally at the end of the month another script create a report on the monthly internet usage.

I thought this was an interesting exercise even if some tools would probably do a better job ($$$). Also we shouldn't take those results too seriously since some protocols like Ajax or HTML5 talk a lot to the servers, keep refreshing pages even if you are not actively working on them.

In this post, I will talk about the last part of this process and how I combine all those files to get a real monthly top domains.


2014/04/05

PowerShell - Get a list of my domain Organizational Units

Quick post, last week my coworker Andrey needed to list all the Organization Units in the domain by Canonical Name. I thought sharing the PowerShell One-Liner magic could save time to some people out there.

In the following examples two methods to retrieve the information using Active Directory and ADSI/NET.



Active Directory Module

I found two ways to get this information using this module
  • Get-ADOrganizationUnit
  • Get-ADObject

First we need to verify if the module is loaded and then search for Cmdlet that could meet our needs.
# Check if the ActiveDirectory module is Loaded
Get-Module -Name ActiveDirevtory

# Check if the ActiveDirectory module is available
Get-Module -Name ActiveDirectory -ListAvailable

# Import the ActiveDirectory module
Import-Module -Name ActiveDirectory

# Find Cmdlets in the ActiveDirectory related to OrganizationalUnit
Get-Command -Module ActiveDirectory -Name *OrganizationalUnit*

2013/10/13

PowerShell - Monitor and Report Active Directory Group Membership Change


UPDATE 2016/05/03: The most recent update is available on Github

See also the related blogpost: http://www.lazywinadmin.com/2013/11/update-powershell-monitor-and-report.html

Today I will update a post that I published at the beginning of last year : Monitor Active Directory Membership changes. I updated the script to add some of the things I learned during the Scripting Games 2013 back in April/May. The script will also create a nice html report and send it via Email.

Basically, the script will monitor the Active Directory groups that you specify and notify you if a change occurred since the last time it checked.



2012/11/01

Create a bunch of DNS Entries using PowerShell and DNScmd.exe

Today I needed to create approx. ~50 DNS A entries.
Each of those also need to have a PTR entry.

Lazy as i am... a quick search for PowerShell DNS module did return some interesting things but none who can create both A and PTR DNS entries at the same time.

So I decided to finally use DNSCMD.exe (full syntax on technet) with powershell.

Requirement: DNSCmd.exe is part of the DNS Server Tools and need to be installed prior to use it. On Windows server you can install it using Add-WindowsFeature RSAT-ADDS-Tools


Here is a quick syntax overview of the Dnscmd.exe that we will be using.

dnscmd.exe <DNSServer> /RecordAdd <DNSZone> <NewEntryName> /CreatePTR A <IPAddress>


First Step: Create a CSV with all the information (in Excel or via PowerShell)
here is an example, save it as DNSEntries.csv (in my case at the root of the C: drive)


Second Step: The Script OneLiner:
Import-CSV -Path "c:\DNSEntries.csv" | ForEach-Object { dnscmd.exe $_.dnsserver /RecordAdd $_.zone $_.name /createPTR $_.type $_.IP }


The output should look like this