Buried iron pipeline is an important part of urban infrastructure. In order to accurately obtain the location information of buried iron pipeline, here, we establish a forward model of magnetic anomaly in buried iron pipeline based on magnetic dipole reconstruction (MDR) method that determines four inversion parameters and two inversion objective functions. The vertical magnetic field data with different proportion noises are taken as observation values respectively to invert the parameters of underground pipeline and its location (buried depth) by using the AM-PSO (adaptive mutation particle swarm optimization) inversion algorithm. The errors of inversion and observation of vertical magnetic field are compared by substituting the inversion parameters into forward formulas. The results show that the AM-PSO inversion algorithm can accurately invert the pipeline depth, and the inversion error of the pipeline depth is less than 5%, which is acceptable in practical engineering. The inversion of the vertical magnetic field can basically coincide with the observed vertical magnetic field of the original model. At the same time, it is verified that the AM-PSO inversion algorithm is insensitive to magnetic anomaly noise data. In this study, the effectiveness of AM-PSO inversion algorithm method for pipeline depth inversion is analyzed, and an effective optimization inversion method is provided for underground iron pipeline depth inversion.