I've had the same problem with my own deploymentscript.
This problem occures if you configure the secure store service application on a multi-server-sharepoint-farm.
I figured out, that the service instance "Secure Store Service" first starts on a diffent App-Server than the one you want to create the Keys for secure store.
Resolution:
You should implement a codesnipet before using the cmdlet 'Update-SPSecureStoreMasterKey' and 'Update-SPSecureStoreApplicationServerKey'.
Here is my Code I've used and it works pretty well:
This problem occures if you configure the secure store service application on a multi-server-sharepoint-farm.
I figured out, that the service instance "Secure Store Service" first starts on a diffent App-Server than the one you want to create the Keys for secure store.
Resolution:
You should implement a codesnipet before using the cmdlet 'Update-SPSecureStoreMasterKey' and 'Update-SPSecureStoreApplicationServerKey'.
Here is my Code I've used and it works pretty well:
Write-Host "Checking Secure Store Service Instance to be online..."
$SecStoreState = (Get-SPServiceInstance | ? {$_.TypeName -eq "Secure Store Service"} | ? {$_.Server.Name -eq $env:ComputerName}).Status
if ($SecStoreState -ne "Online") {
Write-Host "Current state of secure store service application is: $SecStoreState ... trying to bring online now..."
$SecStoreId = (Get-SPServiceInstance | ? {$_.TypeName -eq "Secure Store Service"} | ? {$_.Server.Name -eq $env:ComputerName}).Id.Guid
Start-SPServiceInstance -Identity $SecStoreId
while ($SecStoreState -ne "Online") {
Write-Host "..." -NoNewLine
$SecStoreState = (Get-SPServiceInstance | ? {$_.TypeName -eq "Secure Store Service"} | ? {$_.Server.Name -eq $env:ComputerName}).Status
}
Write-Host ""
}
Write-Host "Done."
Hope this will help you... it does for me.