We can use the below code to achieve the shrink the tempdb size.
use tempdb
go
dbcc shrinkfile(tempdev, 1024)
go
dbcc shrinkfile(templog, 1024)
go
dbcc shrinkfile(tempdb2, 1024)
go
dbcc shrinkfile(tempdb3, 1024)
go
dbcc shrinkfile(tempdb4, 1024)
go
dbcc shrinkfile(tempdb5, 1024)
go
dbcc shrinkfile(tempdb6, 1024)
go
dbcc shrinkfile(tempdb7, 1024)
go
dbcc shrinkfile(tempdb8, 1024)
go
use tempdb
go
dbcc shrinkfile(tempdev, 1024)
go
dbcc shrinkfile(templog, 1024)
go
dbcc shrinkfile(tempdb2, 1024)
go
dbcc shrinkfile(tempdb3, 1024)
go
dbcc shrinkfile(tempdb4, 1024)
go
dbcc shrinkfile(tempdb5, 1024)
go
dbcc shrinkfile(tempdb6, 1024)
go
dbcc shrinkfile(tempdb7, 1024)
go
dbcc shrinkfile(tempdb8, 1024)
go