You would need to do an unmount and then a detach for the datastore.
You can use my function from Test If The Datastore Can Be Unmounted to check if it can be unmounted.
And then you can use Alan's functions from Datastore Mount/Unmount Detach/Attach functions
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference