Complete RackSpace Webmail Inventory

This in the final code for the PowerShell script I wrote to inventory all aspects of the Rackspace REST API, parse the JSON response, and upload the results into SQL. An update to my initial work here.

#========================================================================
# Created with: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.24
# Created on:   10/15/2013 7:50 AM
# Created by:   Rich Hopkins
# Notes:        http://api-wiki.apps.rackspace.com/api-wiki/index.php/Main_Page
#========================================================================

[reflection.assembly]::LoadWithPartialName("System.Data.SqlClient.SqlConnection")
[reflection.assembly]::LoadWithPartialName("System.Data.SqlClient.SqlCommand")

#region Scope Variables

#Set the customerID and domain
$strDomain = "https://api.emailsrvr.com/v0/customers/000000/domains/domain.com"

#Get API keys from RackSpace control panel
$userKey = "your-key-here"
$secretKey = "your-key-here"

#The Powershell UserAgent for HTTP headers
$userAgent = "Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US) WindowsPowerShell/3.0"
#Fake the IE UserAgent by invoking the PSUserAgent .NET Class
#$userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Internetexplorer

#Enable/Disable debugging by commenting the next line
#$debug = $true
$SQLServer = "SQLServerName"
If ($debug) {$SQLDatabase = "Inventory_Dev"}
Else {$SQLDatabase = "Inventory"}

#Create persistant connection to SQL to keep Temp Tables alive
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=$SQLServer;Database=$SQLDatabase;Trusted_Connection=Yes;Integrated Security=SSPI;"
$conn.Open()
$SQLQuery = ""
$SQLCmd = New-Object System.Data.SqlClient.SqlCommand $SQLQuery, $conn
#endregion

#region Begin SQL
$SQLQuery = "CREATE TABLE [dbo].[#vRSExContacts](
    [name] [nvarchar](255) NOT NULL,
    [displayName] [nvarchar](255) NULL,
    [externalEmail] [nvarchar](255) NULL,
    [isHidden] [bit] NOT NULL,
    [firstName] [nvarchar](255) NULL,
    [lastName] [nvarchar](255) NULL,
    [jobTitle] [nvarchar](255) NULL,
    [company] [nvarchar](255) NULL,
    [department] [nvarchar](255) NULL,
    [businessNumber] [nvarchar](255) NULL,
    [homeNumber] [nvarchar](255) NULL,
    [mobileNumber] [nvarchar](255) NULL,
    [faxNumber] [nvarchar](255) NULL,
    [pagerNumber] [nvarchar](255) NULL,
    [addressLine1] [nvarchar](255) NULL,
    [city] [nvarchar](255) NULL,
    [state] [nvarchar](255) NULL,
    [zip] [nvarchar](255) NULL,
    [country] [nvarchar](255) NULL,
    [notes] [nvarchar](max) NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExDLAddresses](
    [name] [nvarchar](255) NOT NULL,
    [emailAddress] [nvarchar](255) NOT NULL,
    [replyTo] [bit] NOT NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExDLMembers](
    [name] [nvarchar](255) NOT NULL,
    [member] [nvarchar](255) NOT NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExDLs](
    [name] [nvarchar](255) NOT NULL,
    [displayName] [nvarchar](255) NULL,
    [isHidden] [bit] NOT NULL,
    [emailAddress] [nvarchar](255) NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExMailbox](
    [name] [nvarchar](255) NOT NULL,
    [replyToAddress] [nvarchar](255) NULL,
    [displayName] [nvarchar](255) NULL,
    [size] [float] NOT NULL,
    [currentUsage] [float] NOT NULL,
    [isHidden] [bit] NOT NULL,
    [enabled] [bit] NOT NULL,
    [lastLogin] [datetime] NULL,
    [firstName] [nvarchar](255) NULL,
    [lastName] [nvarchar](255) NULL,
    [jobTitle] [nvarchar](255) NULL,
    [company] [nvarchar](255) NULL,
    [department] [nvarchar](255) NULL,
    [businessNumber] [nvarchar](255) NULL,
    [homeNumber] [nvarchar](255) NULL,
    [mobileNumber] [nvarchar](255) NULL,
    [faxNumber] [nvarchar](255) NULL,
    [pagerNumber] [nvarchar](255) NULL,
    [addressLine1] [nvarchar](255) NULL,
    [city] [nvarchar](255) NULL,
    [state] [nvarchar](255) NULL,
    [zip] [nvarchar](255) NULL,
    [country] [nvarchar](255) NULL,
    [notes] [nvarchar](255) NULL,
    [customID] [float] NOT NULL,
    [hasBlackBerryMobileService] [bit] NOT NULL,
    [hasActiveSyncMobileService] [bit] NOT NULL,
    [samAccountName] [nvarchar](255) NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExMailboxAddresses](
    [name] [nvarchar](255) NOT NULL,
    [address] [nvarchar](255) NOT NULL,
    [replyTo] [bit] NOT NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExMailboxPerms](
    [name] [nvarchar](255) NOT NULL,
    [emailAddress] [nvarchar](255) NULL,
    [permissionType] [nvarchar](255) NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null

$SQLQuery = "CREATE TABLE [dbo].[#vRSExResources](
    [name] [nvarchar](255) NOT NULL,
    [displayName] [nvarchar](255) NULL,
    [type] [nvarchar](255) NULL
)"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
#endregion

#region Create REST Header

#Note! Must run the Get-Header function each time a new Invoke-RestMethod is run

#This is a breakdown from:
#http://api-wiki.apps.rackspace.com/api-wiki/index.php/Main_Page#C.23
#using the SignMessage() method there I was able to come up with this
#to create the needed SHA1 hash for the HTTP header

#NOTE! The RackSpace wiki is wrong on the header's name
#"X-Api-User-Signature" need to be "X-Api-Signature"

Function Get-SignatureHash([String] $signatureData) {
    $byteArray = [System.Text.Encoding]::ASCII.GetBytes($signatureData)
    $sha =  New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
    $result = $sha.ComputeHash($byteArray)
    $signature = [System.Convert]::ToBase64String($result)
    return $signature
}
 
Function Get-Header {
    $dateTime = (Get-Date).ToString("yyyyMMddHHmmss")
    $signatureData = "$userKey$userAgent$dateTime$secretKey"
    $hashSecret = Get-SignatureHash($signatureData)
    $xApiSignature = "$userKey`:$datetime`:$hashSecret"
    $header = @{"X-Api-Signature"="$xApiSignature"}
    Return $header
}

#endregion

#region Inventory Mailboxes

#Connect to the root of the mailboxes folder to get a count of total machines
$uri = "$strDomain/ex/mailboxes"
$header = Get-Header
$dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
#get number of mailboxes
$totalMailboxes = $dataset.mailboxList.total
#devide total by 100 to assign the value each computer adds to $currentComplete
$eachMailbox = (100 / ($totalMailboxes))
#to be passed as -PercentComplete in Write-Progress
$currentComplete = 0

#mailboxes can only be parsed 250 items at a time, so
for ($i = 0; $i -le $totalMailboxes/250; $i++) {
    
    if ($i -eq 0) {$uri = "$strDomain/ex/mailboxes?size=250"}
    elseif ($i -gt 0) {
        $offset = $i*250
        $uri = "$strDomain/ex/mailboxes?size=250&offset=$offset"
    }
    else {$uri = "$strDomain/ex/mailboxes"}
    
    $header = Get-Header
    $dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
    $index = $dataset.mailboxlist.mailboxes.mailbox
    
    ForEach ($item in $index) {
        
        $userId = $item.name
        $uri = "$strDomain/ex/mailboxes/$userId"
        
        Write-Progress -Activity "Fetching mailbox details" -Status "Processing $userId" -PercentComplete $currentComplete
        
        $header = Get-Header
        $userMailbox = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
        
        $name = $userMailbox.mailbox.name
        $displayName = $userMailbox.mailbox.displayName
        If($displayName -match "'"){$displayName = $displayName -replace "'", "''"}
        $size = $userMailbox.mailbox.size
        $currentUsage = $userMailbox.mailbox.currentUsage
        $isHidden = $userMailbox.mailbox.isHidden
        #$visibleInRackspaceEmailCompanyDirectory = $userMailbox.mailbox.visibleInRackspaceEmailCompanyDirectory
        $isEnabled = $userMailbox.mailbox.enabled
        $lastLogin = $userMailbox.mailbox.lastLogin
        $firstName = $userMailbox.mailbox.contactInfo.firstName
        If($displayName -match "'"){$displayName = $displayName -replace "'", "''"}
        $lastName = $userMailbox.mailbox.contactInfo.lastName
        If($lastName -match "'"){$lastName = $lastName -replace "'", "''"}
        $jobTitle = $userMailbox.mailbox.contactInfo.jobTitle
        $company = $userMailbox.mailbox.contactInfo.company
        $department = $userMailbox.mailbox.contactInfo.department
        $businessNumber = $userMailbox.mailbox.contactInfo.businessNumber
        $homeNumber = $userMailbox.mailbox.contactInfo.homeNumber
        $mobileNumber = $userMailbox.mailbox.contactInfo.mobileNumber
        $faxNumber = $userMailbox.mailbox.contactInfo.faxNumber
        $pagerNumber = $userMailbox.mailbox.contactInfo.pagerNumber
        $addressLine1 = $userMailbox.mailbox.contactInfo.addressLine1
        $city = $userMailbox.mailbox.contactInfo.city
        $state = $userMailbox.mailbox.contactInfo.state
        $zip = $userMailbox.mailbox.contactInfo.zip
        $country = $userMailbox.mailbox.contactInfo.country
        $notes = $userMailbox.mailbox.contactInfo.notes
        $customID = $userMailbox.mailbox.contactInfo.customID
        $hasBlackBerryMobileService = $userMailbox.mailbox.hasBlackBerryMobileService
        $hasActiveSyncMobileService = $userMailbox.mailbox.hasActiveSyncMobileService
        $samAccountName = $userMailbox.mailbox.samAccountName
        $addressList = $userMailbox.mailbox.emailAddressList.emailAddress
        
        ForEach ($address in $addressList) { 
            $emailAddress = $address.address
            $replyTo = $address.replyTo
            If ($replyTo) {$replyToAddress = $emailAddress}
            $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExMailboxAddresses] VALUES ('$name','$emailAddress','$replyTo')"
            #Write-Output $SQLQuery
            $SQLCmd.CommandText = $SQLQuery
            $SQLCmd.ExecuteNonQuery() | Out-Null
            }
        

        $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExMailbox] VALUES ('$name','$replyToAddress'," + `
            "'$displayName','$size','$currentUsage','$isHidden','$isEnabled','$lastLogin'," + `
            "'$firstName','$lastName','$jobTitle','$company','$department','$businessNumber','$homeNumber'," + `
            "'$mobileNumber','$faxNumber','$pagerNumber','$addressLine1','$city','$state','$zip','$country'," + `
             "'$notes','$customID','$hasBlackBerryMobileService','$hasActiveSyncMobileService','$samAccountName')"
        #Write-Output $SQLQuery
        $SQLCmd.CommandText = $SQLQuery
        $SQLCmd.ExecuteNonQuery() | Out-Null
        Start-Sleep -Milliseconds 1000
        
        $uri = "$strDomain/ex/mailboxes/$userId/permissions"
        $header = Get-Header
        $perms = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
        $permlist = $perms.permissionList.permissions.permission
        if ($permlist) {
            ForEach ($perm in $permlist) {
                Write-Progress -Activity "Fetching mailbox details" -Status "Processing permissions for $userId" -PercentComplete $currentComplete
                $emailAddress = $perm.emailAddress
                $permissionType = $perm.permissionType
                $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExMailboxPerms] VALUES ('$name','$emailAddress','$permissionType')"
                #Write-Host $SQLQuery
                $SQLCmd.CommandText = $SQLQuery
                $SQLCmd.ExecuteNonQuery() | Out-Null
                Start-Sleep -Milliseconds 1000
            }
        }
        $currentComplete += $eachMailbox
    }
}
#endregion

Write-Progress -Activity "Mailboxes Complete!" -Completed

#region Inventory Contacts
$uri = "$strDomain/ex/contacts"
$header = Get-Header
$dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
$totalContacts = $dataset.contactList.total
$eachContact = (100 / ($totalContacts))
$currentComplete = 0

for ($i = 0; $i -le $totalContacts/250; $i++) {
    
    if ($i -eq 0) {$uri = "$strDomain/ex/contacts?size=250"}
    elseif ($i -gt 0) {
        $offset = $i*250
        $uri = "$strDomain/ex/contacts?size=250&offset=$offset"
    }
    else {$uri = "$strDomain/ex/contacts"}
    $header = Get-Header
    $dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
    $index = $dataset.contactList.contacts.contact
    
    ForEach ($item in $index) {
        $userId = $item.name
        Write-Progress -Activity "Fetching contact details" -Status "Processing $userId" -PercentComplete $currentComplete
        $uri = "$strDomain/ex/contacts/$userId"
        $header = Get-Header
        $contact = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
        
        $name = $contact.contact.name
        $displayName = $contact.contact.displayName
        $externalEmail = $contact.contact.externalEmail
        $isHidden = $contact.contact.isHidden -as [bool]
        $firstName = $contact.contact.contactInfo.firstName
        $lastName = $contact.contact.contactInfo.lastName
        $jobTitle = $contact.contact.contactInfo.jobTitle
        $company = $contact.contact.contactInfo.company
        $department = $contact.contact.contactInfo.department
        $businessNumber = $contact.contact.contactInfo.businessNumber
        $homeNumber = $contact.contact.contactInfo.homeNumber
        $mobileNumber = $contact.contact.contactInfo.mobileNumber
        $faxNumber = $contact.contact.contactInfo.faxNumber
        $pagerNumber = $contact.contact.contactInfo.pagerNumber
        $addressLine1 = $contact.contact.contactInfo.addressLine1
        $city = $contact.contact.contactInfo.city
        $state = $contact.contact.contactInfo.state
        $zip = $contact.contact.contactInfo.zip
        $country = $contact.contact.contactInfo.country
        $notes = $contact.contact.contactInfo.notes

        $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExContacts] VALUES ('$name','$displayName'," + `
        "'$externalEmail','$isHidden','$firstName','$lastName','$jobTitle','$company','$department'," + `
        "'$businessNumber','$homeNumber','$mobileNumber','$faxNumber','$pagerNumber','$addressLine1'," + `
        "'$city','$state','$zip','$country','$notes')"
        #Write-Output $SQLQuery
        $SQLCmd.CommandText = $SQLQuery
        $SQLCmd.ExecuteNonQuery() | Out-Null
        Start-Sleep -Milliseconds 1000
        $currentComplete += $eachContact
    }
}
#endregion

Write-Progress -Activity "Contacts Complete!" -Completed

#region Inventory Distribution Lists
$uri = "$strDomain/ex/distributionlists"
$header = Get-Header
$dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
$totalDLs = $dataset.distributionlistList.total
$eachDL = (100 / ($totalDLs))
$currentComplete = 0

for ($i = 0; $i -le $totalDLs/250; $i++) {
    
    if ($i -eq 0) {$uri = "$strDomain/ex/distributionlists?size=250"}
    elseif ($i -gt 0) {
        $offset = $i*250
        $uri = "$strDomain/ex/distributionlists?size=250&offset=$offset"
    }
    else {$uri = "$strDomain/ex/distributionlists"}

    $header = Get-Header
    $dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
    $index = $dataset.distributionlistList.distributionlists.distributionlist
    
    ForEach ($item in $index) {
        $userId = $item.name
        Write-Progress -Activity "Fetching DL details" -Status "Processing $userId" -PercentComplete $currentComplete
        $uri = "$strDomain/ex/distributionlists/$userId"

        $header = Get-Header
        $distributionlist = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
        
        $name = $distributionlist.distributionlist.name
        $displayName = $distributionlist.distributionlist.displayName
        $isHidden = $distributionlist.distributionlist.isHidden
        
        $addressList = $distributionlist.distributionlist.emailAddressList.emailAddress
        ForEach ($address in $addressList) { 
            $emailAddress = $address.address
            $replyTo = $address.replyTo
            If ($replyTo) {$replyToAddress = $emailAddress}
            $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExDLAddresses] VALUES ('$name','$emailAddress','$replyTo')"
            #Write-Output $SQLQuery
            $SQLCmd.CommandText = $SQLQuery
            $SQLCmd.ExecuteNonQuery() | Out-Null
        }
        
        $memberList = $distributionlist.distributionlist.memberList.member
        ForEach ($member in $memberList) {
            $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExDLMembers] VALUES ('$name','$member')"
            #Write-Output $SQLQuery
            $SQLCmd.CommandText = $SQLQuery
            $SQLCmd.ExecuteNonQuery() | Out-Null
        }

        $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExDLs] VALUES ('$name','$displayName','$isHidden','$replyToAddress')"
        #Write-Output $SQLQuery
        $SQLCmd.CommandText = $SQLQuery
        $SQLCmd.ExecuteNonQuery() | Out-Null
        Start-Sleep -Milliseconds 1000
        $currentComplete += $eachDL
    }
}
#endregion

Write-Progress -Activity "Distribution Lists Complete!" -Completed

#region Inventory Resources
$uri = "$strDomain/ex/resources"
$header = Get-Header
$dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
$resourceList = $dataset.resourceList.total
$eachResource = (100 / ($resourceList))
$currentComplete = 0

for ($i = 0; $i -le $resourceList/250; $i++) {
    
    if ($i -eq 0) {$uri = "$strDomain/ex/resources?size=250"}
    elseif ($i -gt 0) {
        $offset = $i*250
        $uri = "$strDomain/ex/resources?size=250&offset=$offset"
    }
    else {$uri = "$strDomain/ex/resources"}

    $header = Get-Header
    $dataset = Invoke-RestMethod -Uri $uri -Headers $header -Method Get -ContentType "application/json"
    $index = $dataset.resourceList.resources.resource
    
    ForEach ($item in $index) {
        $name = $item.name
        Write-Progress -Activity "Fetching details for $name" -PercentComplete $currentComplete
        $displayName = $item.displayName
        $type = $item.type

        $sqlQuery = "INSERT INTO [$SQLDatabase].[dbo].[#vRSExResources] VALUES ('$name','$displayName','$type')"
        #Write-Output $SQLQuery
        $SQLCmd.CommandText = $SQLQuery
        $SQLCmd.ExecuteNonQuery() | Out-Null
        Start-Sleep -Milliseconds 1000
        $currentComplete += $eachResource
    }
}
#endregion

#region Drop current tables and replace with temp data
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExContacts]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExContacts] FROM [$SQLDatabase].[dbo].[#vRSExContacts]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExDLAddresses]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExDLAddresses] FROM [$SQLDatabase].[dbo].[#vRSExDLAddresses]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExDLMembers]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExDLMembers] FROM [$SQLDatabase].[dbo].[#vRSExDLMembers]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExDLs]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExDLs] FROM [$SQLDatabase].[dbo].[#vRSExDLs]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExMailbox]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExMailbox] FROM [$SQLDatabase].[dbo].[#vRSExMailbox]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExMailboxAddresses]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExMailboxAddresses] FROM [$SQLDatabase].[dbo].[#vRSExMailboxAddresses]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExMailboxPerms]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExMailboxPerms] FROM [$SQLDatabase].[dbo].[#vRSExMailboxPerms]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "DROP TABLE [$SQLDatabase].[dbo].[vRSExResources]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
$SQLQuery = "SELECT * INTO [$SQLDatabase].[dbo].[vRSExResources] FROM [$SQLDatabase].[dbo].[#vRSExResources]"
$SQLCmd.CommandText = $SQLQuery
$SQLCmd.ExecuteNonQuery() | Out-Null
#endregion

#region Script Cleanup
$SQLCmd.Dispose()
$conn.Close()
$conn.Dispose()
#endregion

Write-Progress -Activity "Done!" -Completed
Advertisements
This entry was posted in Programming and tagged , , , , , . Bookmark the permalink.

2 Responses to Complete RackSpace Webmail Inventory

  1. Pingback: Getting fancy with Write-Progress | Rich Hopkins

  2. Pingback: UPDATED: Inventory Outlook GAL | Rich Hopkins

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s