storage_account = 'xyzacc' ## provide your azure storage account name here ##
file_share = 'myfile' ## provide your file shares file in storage account here which you are going to map ##
storage_key = 'n4y9XnZ1mr0Ki2mCAZKmQD8gn0sjfGwxdCEbhnH+M5tuwvmp1xYw49gmdUMURHjz0Crv8Ws5jBgdcz+AStRtm26g==' ## provide your storage key(Access key) of your storage account here ##
map_letter = 'F' ## provide any alphabet to map (make sure the alphabet is not repeated) ##

import os
import subprocess
import ctypes

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)
with disable_file_system_redirection():
	save_path = 'C:\\ProgramData'
	PATH = r'\\'+storage_account
	file_name = "Mapping.ps1"
	completeName = os.path.join(save_path, file_name)
	file1 = open(completeName, "w+")
	file1.write('Invoke-Expression -Command "cmdkey /add:'+storage_account+'.file.core.windows.net /user: '+storage_account+' /pass: '+storage_key+'"; New-PSDrive -Name '+map_letter+' -PSProvider FileSystem -Root "%s.file.core.windows.net\%s" -Persist'%(PATH,file_share))
	file1.close()
	save_path = 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp'
	PATH = r'\\'+storage_account
	file_name = "Mapping.bat"
	completeName_1 = os.path.join(save_path, file_name)
	file1 = open(completeName_1, "w+")
	file1.write('''
		Powershell.exe -executionpolicy remotesigned -File  '''+completeName)
	file1.close()
	print(map_letter+" Mapped Successfully. Please Logout and Login to see your mapped drive.")
