replace all references to a drive inside the jobs to another drive I have a server where all my sql server backups are currently being saved to the G: drive.

Now there is no enough disk space on drive G: to keep backups for the last 5 days.
I have asked to add another 100 GB to this G: drive but that was not possible, so they gave me another drive instead, the I: drive with extra disk space, as you can see on the picture below.



Now I need to replace all the references to the G: drive in the sql server jobs below to point to the new I: drive.



Suppose I have 3 servers in the same situation, how can I achieve this by T-SQL?
You could try this cursor approach to read rows from dbo.sysjobsteps and execute sp_update_jobstep after doing a search/replace for the string you want to change.

This could also be improved to ONLY update job steps that actually have the string.

DECLARE @cmd VARCHAR(max)
DECLARE @job_id UNIQUEIDENTIFIER
DECLARE @step_id INT
DECLARE @command NVARCHAR(max)

DECLARE _CURSOR CURSOR LOCAL FORWARD_ONLY STATIC READ_ONLY
FOR
SELECT job_id
    ,step_id
    ,command
FROM msdb.dbo.sysjobsteps

OPEN _CURSOR

FETCH NEXT
FROM _CURSOR
INTO @job_id
    ,@step_id
    ,@command

WHILE @@FETCH_STATUS = 0
BEGIN
    SET @command = replace(@command, 'g:', 'I:')

    EXEC msdb.dbo.sp_update_jobstep @job_id = @job_id
        ,@step_id = @step_id
        ,@Command = @command

    FETCH NEXT
    FROM _CURSOR
    INTO @job_id
        ,@step_id
        ,@command
END --End While

CLOSE _CURSOR

DEALLOCATE _CURSOR