What you are experiencing is most likely caching.
PowerShell is keen on caching your instantiated objects, like SPWeb and SPSite, and its content, so if you run everything in one big lump you will see that for example added features wont show up.
A simple way of testing if this is the issue, try to split the script up in two.
Then first execute one script, close the shell, open another and execute that.
If it runs without issues, this is a caching issue!
We have solved this by spawning new processes (Start-Process "PowerShell.exe" ....) based on folders:
010 Solutions
10 Solution
20 Features
020 Etc etc
Each new folder is interpreted as a new PowerShell instance.
This works well, so I would recommend a similar approach. A simpler approach would be to simply spawn a new process to execute your feature provisioning:
$command = "your commands goes here"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
# encoded to avoid encoding and escaping issues
# STA ensures you are running single threaded, important as most SharePoint objects isnt multi threaded
Start-Process powershell.exe -NoLogo -encodedCommand $encodedCommand -STA