Tuesday, January 15, 2019

PowerShell DICOM Scripting

Disclosure: This post is purely technical!
Assumption: you know your way around PowerShell or how to get there and a bit of DICOM and our RZDCX API.

If your system is x64 (probably) than make sure to regsvr32 radix.dll the x64 version.

Let's PowerShell!!!

# download rzdcx
Invoke-WebRequest -Uri http://downloads.roniza.com/rzdcx/ -OutFile ./rzdcx.zip

# unzip it
Expand-Archive ./rzdcx.zip -DestinationPath ./rzdcx

# regsvr32 win32 version
$rzdcx32 = Resolve-Path .\rzdcx\win32\rzdcx.dll
Start-Process regsvr32 -verb runAs -argumentlist $rzdcx32

$rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll
Start-Process regsvr32 -verb runAs -argumentlist $rzdcx64

# Create DICOM Object
$DCM = New-Object -com rzdcx.DCXOBJ

# I assume you have a directory called DICOM with DICOM files in it
$files = @(Get-ChildItem ".\DICOM\*")

# Write headers
"filename, Patient Name, Patient ID"

# For each file extract and print patient name and patient id
foreach ($file in $files) {
  $patname = $DCM.GetElement([int32]::Parse(00100010,'HexNumber')).Value
  $patid   = $DCM.GetElement([int32]::Parse(00100020,'HexNumber')).Value
  Write-Host $file "," $patname "," $patid

Try it!


  1. change:
    $rzdcx64 = Resolve-Path .\rzdcx\win32\rzdcx.dll

    $rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll

  2. Hi Roni, there is a little typo in the script that leads to the following COM exception:

    80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

    It's due to a wrong path to the x64 dll, that should be:

    $rzdcx64 = Resolve-Path .\rzdcx\x64\rzdcx.dll

    Hope this helps

  3. I always get this error... any ideas on what I'm doing wrong?

    PS C:\> # Create DICOM Object
    $DCM = New-Object -com rzdcx.DCXOBJ
    New-Object : Retrieving the COM class factory for component with CLSID {D0F02240-CB2C-468B-9DF5-E0FC4CA94839} failed due to the following error: 80040154 Class not registered (Exception
    from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    At line:2 char:8
    + $DCM = New-Object -com rzdcx.DCXOBJ
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

  4. New File name and location: http://downloads.roniza.com/rzdcx/

  5. newer version change download to ..... http://downloads.roniza.com/rzdcx/