Allscripts Vision User Reporting

This content 2 years old. Please, read this page keeping its age in mind along with the fact technology changes fast and the information on this page me be outdated, not best practice, or plain wrong.

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:

<quickreports>
  <report name=Organizational Unit>
  <database name=v001/>
  <usrlogin name=jdoe01/>
</report>
<quickreports>
$ErrorActionPreference= 'silentlycontinue'
$arr=@{}

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] = @()
$arr.add($key,$value)
}

}
$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)

$xmlDoc.save($fn)

Speak Your Mind

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.