original code from https://communities.vmware.com/docs/DOC-20294