• Microsoft Active Directory Documentation Script Version 1.1 Released

    August 8, 2014

    Active Directory, PowerShell

    I have been working with a very talented and hard-working group of friends to help speed up the runtime of the various documentation scripts. This update of the Microsoft Active Directory (AD) script is the first step towards the goal of having the scripts run as fast as possible and also towards adding Formatted Text and HTML output.

    Here is the list of changes in version 4.2:

    • Cleanup the script’s parameters section
    • Code cleanup and standardization with the master template script
    • Requires PowerShell V3 or later
    • Removed support for Word 2007
    • Word 2007 references in help text removed
    • Cover page parameter now states only Word 2010 and 2013 are supported
    • Most Word 2007 references in script removed:
      • Function ValidateCoverPage
      • Function SetupWord
      • Function SaveandCloseDocumentandShutdownWord
    • Function CheckWord2007SaveAsPDFInstalled removed
    • If Word 2007 is detected, an error message is now given and the script is aborted
    • Cleanup Word table code for the first row and background color
    • Add Iain Brighton’s Word table functions
    • Add parameters for Text and HTML for future updates
    • Cleanup retrieving services and service startup type with Iain Brighton’s optimization
    • Move Services table to new table functions
    • Add numeric values for ForestMode and DomainMode
    • Removed most of the [gc]::collect() as they are not needed
    • Removed the CheckLoadedModule function
    • Added a Requires activedirectory module statement>

    The only fix in this script is for the Forest and Domain Modes. When I was creating this update and testing on my Server 2012 R2 Forest, I noticed that the Forest and Domain modes were no longer text entries and were now numeric values. For example, instead of a Forest mode value of “Windows2012R2Forest”, a “6” was return by the Get-ADForest cmdlet. Same for Get-ADDomain. I added the appropriate numeric values to both Switch statements.

    I have added new output parameters for Formatted Text and HTML (for future updates). The parameters section was getting very ugly looking and over complicated. Turns out I was making that section much more difficult than it needed to be. After simplifying the code, the help text for the parameters, to me, looks much better.

    SYNTAX
        F:\ADDS_Inventory_V1_1.ps1 [-MSWord] [-Hardware] -ADForest <String> [-ComputerName <String>] [-Services]
        [-AddDateTime] [-CompanyName <String>] [-CoverPage <String>] [-UserName <String>] [<CommonParameters>]
    
        F:\ADDS_Inventory_V1_1.ps1 [-PDF] [-Hardware] -ADForest <String> [-ComputerName <String>] [-Services]
        [-AddDateTime] [-CompanyName <String>] [-CoverPage <String>] [-UserName <String>] [<CommonParameters>]
    
        F:\ADDS_Inventory_V1_1.ps1 [-Text] [-Hardware] -ADForest <String> [-ComputerName <String>] [-Services]
        [-AddDateTime] [<CommonParameters>]
    
        F:\ADDS_Inventory_V1_1.ps1 [-HTML] [-Hardware] -ADForest <String> [-ComputerName <String>] [-Services]
        [-AddDateTime] [<CommonParameters>]
    

    This script now requires PowerShell version 3 or later and Word 2007 is no longer supported.

    This script contains the code for Iain’s new table functions. Iain’s table functions populate Word tables about 95% faster than my old method. Over time, I will move all the Word tables in this script to use Iain’s new table functions. I have already moved the Hardware and Services tables to the new Word table functions. Eventually, HTML output will be added once someone comes up with a generic way to create HTML output that works in the master template script.

    When I was creating the original DHCP and Active Directory scripts, I found out the code I was using for the header row in a Word table was too verbose. I learned how to reduce the lines of code needed to set the header row and give it a background color and make the text bold.

    You can always find the most current script by going to https://carlwebster.com/where-to-get-copies-of-the-documentation-scripts/

    Thanks

    Webster

    About Carl Webster

    Webster is a Sr. Solutions Architect for Choice Solutions, LLC and specializes in Citrix, Active Directory and Technical Documentation. Webster has been working with Citrix products for many years starting with Multi-User OS/2 in 1990.

    View all posts by Carl Webster

    10 Responses to “Microsoft Active Directory Documentation Script Version 1.1 Released”

    1. Jason Lehr Says:

      Any good way of getting this to run as a scheduled task and save to a UNC path?

      Reply

      • Carl Webster Says:

        It is all command line so should be easy to run as a scheduled task. Output is another matter. I could add yet another parameter so you can specify an output path.

        Thanks

        Webster

        Reply

        • Jason Lehr Says:

          I was able to work around it by putting the absolute path in the strings starting on line 3099: (e.g.: changed “$($pwdpath)\$($OutputFileName).docx” to “\\SERVERNAME\SHARE\$($OutputFileName).docx”)

          Then since I have multiple forests I use another script and have one line per domain using invoke-expression -Command C:\scripts\ADDS_Inventory_V1_1.ps1 -parameters…

          This is an amazing script by the way. There is one thing where some of the tables skew over the right side margin I am going to play with some of the other supported styles to see if any work better than the default. If I can only get this to plug into my custom DOCX template I’d be 100% automated!

          Reply

          • Carl Webster Says:

            I have run the script against a lot of AD Forests and have never had a table right off the right margin. Could you sanitize a report and send me a copy of the bad tables?

            Webster@carlwebster.com

            Thanks

            Webster

            Reply

        • Jason Lehr Says:

          Well spent quite a bit of time battling this (running as scheduled task), and finally it was the Powershell creating the Word object that was the issue. After a bit of research I have it running using the following settings:
          1) Full path to powershell.exe: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE
          2) I call a kick-off script, partially because I am running an instance against a few different forests but also because I was (maybe)having issues encapsulating the parameters: e.g. -ExecutionPolicy bypass -file “C:\scriptfolder\CallADReports.ps1”
          3) THE BIG ONE: Create a “Desktop” subfolder in C:\windows\sysWOW64\config\systemprofile (for x86 in C:\windows\system32\config\systemprofile)- I created in both. Even though you are running your task as an account it actually runs in the context of “SYSTEM” and needs access to that profile folder. This fools the task into believing it is like any user profile. Give your service account full control of that Desktop Folder too!

          Still battling the cover pages, would love to see the ability to support custom cover pages- which I tried by copying one of the supported ones and plugging the name into the script but no dice… Thanks again Carl look forward to future updates on this!

          Reply

          • Carl Webster Says:

            I have tried, in vain, several times to get the scripts to work with custom templates and cover pages and never got it to work.

            Webster

            Reply

    2. Pete Petersen Says:

      Carl, I missed a step. Maybe an update to the pre-req doc would be helpful for other users who are as inexperienced as I am with PowerShell. I missed the importing the AD module:

      Import-Module ActiveDirectory

      Following the RSAT install.

      Cheers!

      Reply

      • Carl Webster Says:

        Version 1.0 of the AD script has code in it to make sure the ActiveDirectory module is loaded. If the module is not loaded and cannot be found, the script will abort with the following message:

        The ActiveDirectory module could not be loaded.
        Script cannot continue.

        Version 1.1 of the AD script uses the following to allow PowerShell to enforce the required module is loaded. If not, I let PowerShell the error.

        #Requires -Version 3.0
        #requires -Module ActiveDirectory

        I do not understand how you got past that requirement in the script.

        Thanks

        Webster

        Reply

    3. Pete Petersen Says:

      Carl, forgive me if this question is too simple/elementary.

      When I run the script, either from a W7 box with RSAT installed, or on the Domain Controller itself, I get “Could not find a forest identified by: mydomain.local”

      We only have one domain, and I assume it’s the root and therefore represents the forest as well…?

      Reply

      • Carl Webster Says:

        From your computer, open a PowerShell session and type in:

        Get-ADForest -Identity mydomain.local

        If you passed a domain controller name for the -ComputerName parameter, enter this:

        Get-ADForest -Identity mydomain.local -Server DCName

        What happens?

        Thanks

        Webster

        Reply

    Leave a Reply