Martijn,
In looking at the MSDN docs, it appears that $app.password is looking for a string, not a SecureString. There are three ways you can do this. You could replace:
$app.username = "winadmin" $password = read-host "Enter a Password:" -assecurestring
with:
$credential = Get-Credential -Credential "winadmin"
$app.username = $credential.username
$app.password = $credential.GetNetworkCredential().Password #This returns the password to cleartext
or you could:
$app.username = "winadmin" $password = read-host "Enter a Password:" -assecurestring
$app.password = (New-Object System.Management.Automation.PSCredential $app.username, $password).GetNetworkCredential().Password
#which essentially does the same thing.
finally, you could:
$app.password = [Runtime.InteropServices.Marshal]:

trToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
#which is a bit more difficult to understand, in my opinion
Of the three, the first is the easiest and makes best use of the cmdlet. Hope this helps!