sabinio / salt

SQL Agent depLoy Tasks - Takes SQL Server Agent Jobs stored in XML and deploys them to a SQL Server Instance.
MIT License
13 stars 1 forks source link

“User is not owner of Schedule” error even though the user is the owner of the schedule. #17

Closed RichieBzzzt closed 6 years ago

RichieBzzzt commented 6 years ago

The problem is that both of the SID variables are created from a varbinary column in SQL Server so are byte arrays. –notmatch doesn’t work as presumably expected in that case as shown below.

[byte[]] $CurrentUserSid = 1,2,3
[byte[]] $JobScheduleOwnerSid = 1,2,3

Clear-Host

if ($CurrentUserSid -notmatch $JobScheduleOwnerSid)
{
Write-Host "Not owner of the schedule - current method"
} 

This will need to be changed to something like….

if(@(Compare-Object $CurrentUserSid $JobScheduleOwnerSid -SyncWindow 0).Length -gt 0)
{
Write-Host "Not owner of the schedule - alternate method"
}

This path is only hit when the job has an existing schedule whose name does not exist in the job XML so probably not that common an occurrence.

RichieBzzzt commented 6 years ago

Fixed as of release 1.1.2562