Q: Powershell: redirect output from "NET share" or "Remove-SmbShare" I want to delete all shares and store the output of the command in a variable
Hopefully you can help me!
How do I delete a share?
  Invoke-Expression "Remove-SmbShare -Force -Name $name"

or
  NET SHARE $name /delete 

Thanks!
edit:
I know that I can redirect the output to a File, but I do want it to redirect it directly into a variable.
 NET SHARE i$ /delete *> "C:\workspace\output.txt"

Why do I want to delete shares via Powershell? 
Forced shares via company rules and I want to get rid of them directly after the login

A: If you are asking in the powershell section if you should use a executable or a commandlet the answer is pretty obvious: the commandlet.
Remove-SmbShare does not generate output for successful execution so you will have to work around that.
What you could do is something like this:
$names = "TestShare","TestShare2"
$success = @()
foreach($name in $names){
    try {
        Remove-SmbShare $name -force -Erroraction Stop
        $success += $true
    } catch {
        $success += $false
    }
}

Afterwards you will have two arrays with corresponding indexes. Alternatively you could also add a string to the success array like so $success += "$name $true" but you will figure that out on your own.
