Reputation: 109
I have a script that can remotely query computers for their SMBIOSVersion, and then outputs the ComputerName and SMBIOSVersion like so...
ComputerName SMBIOSBIOSVersion ------------ ----------------- SD010E7C6B28A08 P08 Ver. 02.18
I would like to add a portion to the script that will query the machine to see if anyone is logged on or not, and then format that output in a simple yes or no format like so.
ComputerName SMBIOSBIOSVersion UserLoggedOn ------------ ----------------- ------------ SD010E7C6B28A08 P08 Ver. 02.18 Yes
I've tried modifying the output of psloggedon.exe
to accomplish this task but have so far been unsuccessful.
Here is what I have so far:
function Get-SMBIOSVersion {
[CmdletBinding()]
Param(
[Parameter()]
[ValidateScript({Test-Connection -ComputerName $_ -Quiet -Count 1})]
[ValidateNotNullOrEmpty()]
[string[]]$ComputerName = $env:COMPUTERNAME
)
foreach ($comp in $ComputerName) {
$output = @{ 'ComputerName' = $comp }
$output.SMBIOSBIOSVersion = (Get-WmiObject Win32_Bios -ComputerName $comp).SMBIOSBIOSVersion
[PSCustomObject]$output
}
}
Write-Host "Please select the machine list"
function Get-FileName($InitialDirectory) {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $initialDirectory
#$OpenFileDialog.Filter = "CSV (*.csv)| *.csv|TXT (*.txt)| *.txt"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.Filename
}
$inputfile = Get-FileName "C:\temp\Scripts"
$ComputerList = get-content $inputfile
$ErrorActionPreference = "SilentlyContinue"
cd C:\PSTOOLS
foreach ($Computer in $ComputerList) {
Get-SMBIOSVersion $Computer
}
Upvotes: 0
Views: 230
Reputation: 7479
you can use CIM/WMI to get the current locally logged in user. it does not show remote users such as RDP stuff. like this ...
(Get-CimInstance -ClassName CIM_ComputerSystem -ComputerName 'LocalHost').UserName
if you can, you may prefer to change your BIOS call via WMI to use CIM. the CIM calls are somewhat faster ... and if you need to access datetime info, they use datetime instead of the WMI filetime stuff. something like this ...
(Get-CimInstance -ClassName CIM_BIOSElement -ComputerName 'LocalHost').SMBIOSBIOSVersion
Upvotes: 1
Reputation: 111
if you want to see if anyone is logged try with this [its just an idea how to get the information]
qwinsta /Server:$server | ? -f {if ($_ -like "*Console*") {$ConsoleSession= $true}}
$ConsoleSession
$ConsoleSession will be true or False you can adjust output for more informations you want to have
Upvotes: 0