What are my options for defending a ledge once the enemy grabs it? I know Dsmash sometimes hits, sometimes not. Same for dtilt.
Not sure if those are the best options or not.
If an enemy has already grabbed a ledge, there is not a lot you can do safely near the ledge because of their invincibility. Once you play with someone who can ledgedash well, you'll learn that you should keep a good distance from the ledge and instead threaten their getup options. It's very easy and effective to stand outside of their initial range and threaten f-tilt and dash grab.
You can short hop needle the ledge but even that is not safe, and it's only effective if you catch their jump. You want to hit them with needles as they are jumping to the ledge but not really when they're already hanging there.
Remember that if you don't put yourself in a lot of danger by being close to the ledge, you are in a very dominant position because you are outside of the enemy's immediate threats but you can punish a lot of their actions on reaction. I'm sure there has been a time where you played someone, let's say a Marth who made you feel cornered by the ledge just by standing there. You can do the same thing.
The next time you play, I suggest you to try to resist the urge to go near the ledge if the enemy is already there and stay a good distance from it, threaten with moves that are hard to punish like f-tilt or spaced aerials and try to resist the urge to hard commit with something like dash attack or d-smash.
D-smash is definitely not a good option near the ledge in general but it can work okay against newer players or as a hard read. In order to hit them at the ledge, you need to be standing right at the edge because d-smash has a small hitbox right below sheik. Again, if you do this regularly, better players will bait it out and punish you hard for it.