save powershell script in array


$xl = new-object -com "excel.application"
$xl.visible = $true
$xl.displayalerts = $false
$wb = $xl.workbooks.open("c:\temp\asif.xlsx")
$ws = $wb.sheets.item(1)
$cols=$ws.usedrange.columns.count
$myarray=@()
write-host "cols=$cols"
$rows = $ws.usedrange.rows.count
write-output "rows=$rows"
for($col=1;$col -le $cols;$col++){
   
 for($row=1;$row -le $rows;$row++){
  $ws.cells.item($row, $col).text
        $valarray = $ws.cells.item($row, $col).text
        @myarray+=$valarray  # this error comes please help
 }
}
$wb.close()
$xl.quit()
#release com objects (otherwise leave running excel process behind)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($wb)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($xl)

hi,

i'm not sure question is, try changing @myarray $myarray (inside of loop).


don't retire technet! - (maybe there's still chance hope, on 12,000+ strong , growing)




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file