×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Script to export to excel

Script to export to excel

Script to export to excel

(OP)
I Have below script:-- looking for help to convert the output to excel format

CODE --> Powershell

$servers = get-content “c:\list.txt”
foreach ($server in $servers)
{
$server
$command = “quser /server:” + $server
invoke-expression $command 
} 

when executed getting in below format the output.

CODE --> text

server1
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 Vdw231                ica-tcp#8           7  Active          .  11/5/2012 10:40 AM
 Vdw232                ica-tcp#60         16  Active      16:18  11/5/2012 2:22 PM
 Vdw233                ica-tcp#71          3  Active          .  11/6/2012 6:10 AM
 Vdw234                ica-tcp#72          1  Active          3  11/6/2012 6:59 AM
 Vdw235                ica-tcp#73          5  Active          .  11/6/2012 6:59 AM
 Vdw236                rdp-tcp#74          2  Active          .  11/6/2012 7:07 AM
server2
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 Vdw210                ica-tcp#44         14  Active      13:50  11/5/2012 9:03 AM
 Vdw211                ica-tcp#67          6  Active          .  11/6/2012 1:56 AM
 Vdw212                ica-tcp#70          1  Active         45  11/6/2012 6:34 AM
 Vdw213                ica-tcp#72          9  Active         25  11/6/2012 6:53 AM
 Vdw214  
server3
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 Vdw215                rdp-tcp#131         1  Active         19  11/5/2012 1:42 AM
 Vdw216                rdp-tcp#132         4  Active         17  11/5/2012 2:06 AM
 Vdw217                rdp-tcp#143         6  Active          .  11/6/2012 3:31 AM 
My requirement is i wanted to convert this output to excel format for submitting to management. Below is the excel format that i am thinking...to have from above script...

ServerName USERNAME SESSION NAME ID STATE IDLE TIME LOGON TIME
server1 Vdw231 ica-tcp#8 7 Active . 11/5/2012 10:40
Vdw232 ica-tcp#60 16 Active 16:18 11/5/2012 14:22
Vdw233 ica-tcp#71 3 Active . 11/6/2012 6:10
Vdw234 ica-tcp#72 1 Active 3 11/6/2012 6:59
Vdw235 ica-tcp#73 5 Active . 11/6/2012 6:59
Vdw236 rdp-tcp#74 2 Active . 11/6/2012 7:07
server2
Vdw210 ica-tcp#44 14 Active 13:50 11/5/2012 9:03
Vdw211 ica-tcp#67 6 Active . 11/6/2012 1:56
Vdw212 ica-tcp#70 1 Active 45 11/6/2012 6:34
Vdw213 ica-tcp#72 9 Active 25 11/6/2012 6:53
server3
Vdw215 rdp-tcp#131 1 Active 19 11/5/2012 1:42
Vdw216 rdp-tcp#132 4 Active 17 11/5/2012 2:06
Vdw217 rdp-tcp#143 6 Active . 11/6/2012 3:31


RE: Script to export to excel

(OP)
Can i also do some filtering before saving to excel to a specific column?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close