How to get a bone’s Pose Mode transform matrix
The PoseBone.matrix_basis attribute works as expected. Use the matrix's decompose method to extract the quaternion rotation.

To test the script, open up a new file, delete everything and create an armature.

import bpy

for b in bpy.context.scene.objects.active.pose.bones:
    # use the decompose method
    loc, rot, sca = b.matrix_basis.decompose()
    # or use the to_quaternion method
    rot = b.matrix_basis.to_quaternion()

    print(rot)


Result: &lt;Quaternion &lt;w=1.0000, x=0.0000, y=0.0000, z=0.0000&gt;&gt;

If you want to use the matrix for other things you can easily make a copy with the matrix.copy() method.