In Act I, Scene 1 of Shakespeare's Hamlet, the guard watches the shores of Denmark as there is an fearful apprehension that Norway's Fortinbras, son of the late king who was slain by King Hamlet, who took his lands, plans an attack in order to retrieve such lands. This guard has seen during their watches a spectre; however, Horatio says that Marcellus and Bernardo and Francisco are merely imagining it. So, Marcellus has entreated Horatio come and watch with them.
The ghost, in fact, does appear, looking like the dead King Hamlet. Horatio orders it to speak, but the ghost disappears into the night; Horatio believes that the ghost of the king "bodes some strange eruption to our state" (1.1.70). Again the spectre appears and Horatio urges it to speak to him, telling if it knows anything of Denmark's fate. As the ghost starts to move away, Horatio calls to Marcellus, telling him to stop it:
Shall I strike at it with my partisan?
Do, if it will not stand. (1.1.139-140)
But, Bernardo and Horatio find themselves stabbing at the air. Marcellus concludes,
We do it wrong, being so majestical
To offer it the show of violence;
For it is as the air, invulnerable,
And our vain blows malicious mockery (1.1.143-145)
By stabbing at the ghost of King Hamlet, Bernardo and Horatio make a mockery of killing the majestical king, for he is already dead and, like the air that they have stabbed invulnerable, or untouchable and incapable of being wounded or killed since it is already dead. The phrase quoted above in the question is precisely a simile as mentioned in the previous post since the comparison is stated using as (which means like).
This is a passage that is found in Act I, Scene 1. The words are spoken by Marcellus as he and the others are watching the ghost.
The word "invulnerable" means "unable to be hurt" or something like that. So if something is invulnerable, you cannot do any harm to it. So in this passage, they are saying that something (the ghost, in this case) is something that they cannot hurt. They cannot hurt it anymore than they could hurt the air.
In my opinion, this is not really a metaphor because it uses the word "as." To me, this is actually a simile because it is coming right out and saying that the ghost is like the air.