# Powershell Script help

Hi

I need to check who is logged onto various Blade Workstation's using a Powershell Script and output to a text file so that we can then format the text file to HTML using Powershell

We use this to help Users see what Blades are available who is logged in if they require a certain Blade.

I have used a .bat file in the past and cleaned the output file in Powershell, But would like to clean up the process with just one script.

One issue I have found when looking online for a solution is the ability to have the UserName field show as "No Users" when No user is logged on.

We use the "No User" to assign a Blade is Free icon in the HTML page.

I have tried to use the eq $Null but have failed so far. Requirements Hostname UserName + "No User" Time logged in Any help on finding a solution would be very much appreciated. Thank you LVL 1 Asked: ###### Who is Participating? Batchelor, Developer and EE Topic AdvisorCommented: Testing against$Null works for me. But we can also do it the other way round:
gwmi -computer (gc c:\temp\ee\computers.txt) Win32_ComputerSystem |
select @{n='Blade'; e={$_.Name}}, @{n='User'; e={ if ($_.UserName) { $_.Username } else { "No user" }} }  0 Batchelor, Developer and EE Topic AdvisorCommented: Can you provide more details how you do it now (e.g. the batch), and what you tried exactly? 0 Author Commented: Hi We use the following batch file winrs -r:pcbw177 hostname >> C:\Blades\UK\UK_Blades.txt 2>&1 Winrs -r:pcbw177 quser >> C:\Blades\UK\UK_Blades.txt 2>&1 It will provide the following to a txt file PCBW00012 No User exists for * PCBW00013 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME nimar console 3 Active none 2/4/2015 2:52 PM We then clean the txt file via Powershell 0 Author Commented: I have looked at many scripts but the below is close Get-Content c:\myscripts\computers.txt | ForEach-Object {gwmi -computer$_ -class win32_computerSystem} | fl Name, UserName |
out-file c:\myscripts\output8.txt


It gives the following output

Name     : PCBW180

Name     : PCBW00013
0

Author Commented:
That works :)

Is there away to get the date/time stamp?

Thank you
0

Author Commented:
Quick and helpful thank you Qlemo
0

Batchelor, Developer and EE Topic AdvisorCommented:
Getting login time is more complex. You need to query Win32_LogonSession with the logon ID, which is associated to the name by another WMI object I cannot remember ...
0

Author Commented:
Hi Qlemo

Login time isn't that important so it can be removed.

Is there away to have the USERNAME in Uppercase

DE-PROD\bendb = DE-PROD\BENDB

Thank you for your help with this, your time and effort is very much appreciated
0

Author Commented:
any ideas how we can deal with the following error

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

we have an issue with the Blade and it would be good to assign an "issue" symbol on the HTML page

Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.