I have tried this code to attach a document in custom list for sharepoint online, but it is not working.


	$site = [Microsoft.SharePoint.SPSite]("Your site name") 
	$web = $site.OpenWeb() 
	$list = $web.Lists["Your List name"] 
	$item = $list.GetItemById(Your Id) 
	AddAttachment $item "Your Document Name" 
	
	function AddAttachment($item, $filePath) 
	{ 
		$bytes = [System.IO.File]::ReadAllBytes($filePath) 
		$item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes) 
		$item.Update() 
	}