Allscripts Vision User Reporting

A quick Powershell script I hacked together that will enumerate all Active Directory users, and build an XML file for an application I wrote that generates user reports for a specific application.

The output file format is similar to:

  <report name=Organizational Unit>
  <database name=v001/>
  <usrlogin name=jdoe01/>
$ErrorActionPreference= 'silentlycontinue'

foreach ($usr in Get-ADUser -Filter *  | select samaccountname) {

$user = get-aduser -identity $usr.samaccountname -ErrorAction SilentlyContinue
$userou = (($user.DistinguishedName -split =,2)[-1].split(,)[1] -split =,2)[-1]

$key = $userou
$value = $usr.samaccountname

if ($arr.ContainsKey($userou)) {
$arr[$userou] += $usr.samaccountname 
} else {
$arr[$userou] = @()

$foo = <?xml version=1.0 encoding=utf-8?>`r`n
$foo += <quickreports>`r`n

$foo += foreach ($ou in $arr.keys) {

    write-output   <report name=$ou>`r`n

    foreach ($u in $arr[$ou]) {
                if ($u.contains(01)) {
                    write-output <database name=v001/>`r`n
                } elseif ($u.contains(04)) {
                    write-output <database name=v004/>`r`n
                } else { 
                    write-output <database name=/>`r`n
        write-output <usrlogin name=$u/>`r`n
    write-output </report>`r`n

$foo += </quickreports>

$foo | out-file quickreport.xml

# for some reason the outputted file was dumping 0x00 into the file.  Eventually
# I'll clean all this up and just write all the attributes and elements from up above
# but now is not the time as this is just a quick and dirty POC

$fn = quickreport.xml
$xmlDoc = [system.xml.xmldocument](get-content $fn)


Add a Comment

Your email address will not be published. Required fields are marked *