$sn = Read-Host -Prompt "请输入员工号|序列号|资产号" $xl = New-Object -ComObject "Excel.Application" $cmdbwb = $xl.Workbooks.Open("F:IvanHZCMDB.xlsx") $cmdbwss = "01--GE DST", "01--BBG DST", "01--Non GE DST" ForEach ($cmdbwsname in $cmdbwss) { $cmdbws = $cmdbwb.Worksheets.Item($cmdbwsname) $row = $cmdbws.cells.find($sn).row if($row -ne $null) { [pscustomobject][ordered]@{ EmployeeNo = $cmdbws.range("A$row").text EmployeeName = $cmdbws.range("B$row").text SeatNo = $cmdbws.range("C$row").text Project = $cmdbws.range("D$row").text Model = $cmdbws.range("E$row").text ServiceTag = $cmdbws.range("F$row").text FinanceNo = $cmdbws.range("G$row").text RAM = $cmdbws.range("H$row").text Hostname = $cmdbws.range("I$row").text }}} $xl.Quit() $cmdbws = $null $cmdbwb = $null $xl = $null [GC]::Collect() [Console]::Readkey() | Out-Null Exit