Skip to main content

Just for fun - Storing BLOB files as XML

So, one of the reasons why I like to teach PowerShell is that every once and a while, someone comes up with an unusual idea. So here it goes.  Can you save a BLOB file in an XML file?  This is strictly for the sake of theory.  In the process, we discovered some different behavior of Get-Content.
Off the top of my head, the only way that I knew how to create a BLOB file is with an Offline Domain Join.  Here is the Wikipedia definition of a BLOB:

A Binary Large Object (BLOB) is a collection of binary data stored as a single entity in a database management system. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob.

An Offline Domain Join allows you to create an object in Active Directory for a new client without the client being available.  It also allows to client to be configured to join the domain once it is able to contact a Domain Controller.  To get this to work, you need to create a BLOB file with the DJoin command and send that BLOB file to the client. 

So, here we go….

This will execute the provisioning portion of an ODJ.  Since this is a PowerShell class, I used Invoke-Expression.

# Offline Domain Join

Invoke-Expression -Command "djoin /provision /domain adatum.com /machine LON-SVR1 /SaveFile C:\PS\DJoin.txt"


Here is what the BLOB file looks like.  Not much to look at.
# View the BLOB
Get-Content -Path C:\ps\DJoin.txt
ARAIAMzMzMyAAwAAAAAAAAAAAgABAAAAAQAAAAQAAgABAAAAAQAAAFgDAAAIAAIAWAMAAAEQCADMzMzMSAMAAAAAAACQJ/RsADrzbABE82xg3
PJsDAAOAJB682wUABYAAEfzbBQAFgCAQvNse3803ox6YU6lMRUWqlSC3kA582ywnPJsgETzbAEAAAB7fzTejHphTqUxFRaqVILewEDzbMA+82
z98QDg4DH0bGAq9GwAAAAACwAAAAAAAAALAAAAYQBkAGEAdAB1AG0ALgBjAG8AbQAAAAAACQAAAAAAAAAJAAAATABPAE4ALQBTAFYAUgAxAAA
AAAB5AAAAAAAAAHkAAAAlAGsAbQBjAEsAVQAlACAAegBgAEsAWQAkAEIARABaADcASABmAGAAbABSAHgAKQBTAGMAWABWAF0AXwA2AEkAJQBi
AE4AYQBdAGgAbgAiADMANgA/AFcAYwBdAHoAcwBtAEoAIQBJACgANwB5AFwAVwAhADgAXQA9AGMAXABEAEoAUwBEADsAIwBGACsAVwAwADEAd
gByADsAOgBXACsALQBmAD0AZABlAFcAIwBeADcAKgAwAD0AKwA/ACIAKwB3ADMAbgBrADYATgAhAE4AUABMAGUAdABiAEwAKQBZACcAQwBCAG
AAWwBXAGMARAAAAAAABwAAAAAAAAAGAAAAQQBEAEEAVABVAE0ACwAAAAAAAAAKAAAAQQBkAGEAdAB1AG0ALgBjAG8AbQALAAAAAAAAAAoAAAB
BAGQAYQB0AHUAbQAuAGMAbwBtAAQAAAABBAAAAAAABRUAAABDGsFH3xdvCMGS/FIVAAAAAAAAABUAAABcAFwATABPAE4ALQBEAEMAMQAuAEEA
ZABhAHQAdQBtAC4AYwBvAG0AAAAAAAsAAAAAAAAACwAAAFwAXAAxADAALgAwAC4AMAAuADIAAAAAAAsAAAAAAAAACwAAAEEAZABhAHQAdQBtA
C4AYwBvAG0AAAAAAAsAAAAAAAAACwAAAEEAZABhAHQAdQBtAC4AYwBvAG0AAAAAABgAAAAAAAAAGAAAAEQAZQBmAGEAdQBsAHQALQBGAGkAcg
BzAHQALQBTAGkAdABlAC0ATgBhAG0AZQAAABgAAAAAAAAAGAAAAEQAZQBmAGEAdQBsAHQALQBGAGkAcgBzAHQALQBTAGkAdABlAC0ATgBhAG0
AZQAAAAAAAAAAAAAA 

# Save as an CliXML
Get-Content -Path C:\ps\DJoin.txt | Export-Clixml -Path c:\ps\DJoin.xml

# View the XML File
Notepad C:\ps\DJoin.xml
  
Unfortunately, I cannot display the XML file in this blog.  Go ahead and take a look at it. Keep scrolling down, something is not right.  This is what threw my off.  Take a close look.  There is a lot more information here than the String object sent to Export-CliXML.  As a matter of fact, I’m seeing the size of my hard drive!!!! The reason is that Get-Content added a few note properties.

PS C:\> Get-Content -Path C:\ps\DJoin.xml | Get-Member -MemberType NoteProperty


   TypeName: System.String

Name         MemberType   Definition                                                                        
----         ----------   ----------                                                                         
PSChildName  NoteProperty System.String PSChildName=DJoin.xml                                               
PSDrive      NoteProperty System.Management.Automation.PSDriveInfo PSDrive=C                                
PSParentPath NoteProperty System.String PSParentPath=C:\ps                                                  
PSPath       NoteProperty System.String PSPath=C:\ps\DJoin.xml                                              
PSProvider   NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.PowerShell.Core\F...
ReadCount    NoteProperty System.Int64 ReadCount=1                                                          


These are not part of a normal string object.  These note properties are responcible for some of the excess information in the XML.  At this point, I was thinking that this is going to fail at the client end.  In any case, the provisioning worked:
PS C:\ps> Get-ADComputer -Identity LON-SVR1


DistinguishedName : CN=LON-SVR1,CN=Computers,DC=Adatum,DC=com
DNSHostName       : LON-SVR1.Adatum.com
Enabled           : True
Name              : LON-SVR1
ObjectClass       : computer
ObjectGUID        : b2c4be2e-bcbb-48cc-be8c-18313600d8ac
SamAccountName    : LON-SVR1$
SID               : S-1-5-21-1203837507-141498335-1392284353-4103
UserPrincipalName : 

Next we manually copied the XML file to the destination client and executed these commands.
# Create a new directory.
New-Item -Path c: -Name PS -ItemType Directory

# Import the XML File
Import-Clixml -Path C:\ps\DJoin.xml | Out-file -FilePath c:\ps\djoin.txt

Invoke-Expression -Command "djoin /requestodj /loadfile c:\ps\djoin.txt  /WindowsPath c:\Windows /localos"

We received the normal restart required command and after the restart, the client was on the domain. Surprise!!!!!
OK, again, this was just for the sake of theory.  No practical usage was implied.  We were just having some fun.






Comments

Popular posts from this blog

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for PowerShell V3, th

Return duplicate values from a collection with PowerShell

If you have a collection of objects and you want to remove any duplicate items, it is fairly simple. # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   # Remove the duplicate values. $Set1 | Select-Object -Unique 1 2 3 4 5 6 7 What if you want only the duplicate values and nothing else? # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   #Create a second collection with duplicate values removed. $Set2 = $Set1 | Select-Object -Unique   # Return only the duplicate values. ( Compare-Object -ReferenceObject $Set2 -DifferenceObject $Set1 ) . InputObject | Select-Object – Unique 1 2 This works with objects as well as numbers.  The first command creates a collection with 2 duplicates of both 1 and 2.   The second command creates another collection with the duplicates filtered out.  The Compare-Object cmdlet will first find items that are diffe

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.