Product: PowerShell Universal
Version: 1.4.6
###################################################################3
New-UDCard -Title "Informacja" -Content {
"asdasd"
}
New-UDGrid -Container -Children {
$computerList = Get-Content -Path "D:\list.txt"
foreach ($computerName in $computerList) {
New-UDGrid -Item -Children {
New-UDDynamic -Content {
function Test-Computer {
[CmdletBinding()]
param (
[Parameter(HelpMessage = "ComputerName to test availabilitiy", ValueFromPipeline)]
[Alias("Computer")]
[string]$computerName
)
begin {
function Get-LocalGroupMembership {
[CmdletBinding()]
param (
[Parameter(HelpMessage = "ComputerName do check group membership", ValueFromPipeline)]
[Alias("Computer")]
[string]$computerName,
[Parameter(HelpMessage = "GroupName to check members")]
[Alias("Group")]
[string]$groupName
)
$members = @($([ADSI]"WinNT://$computerName/$groupName,group").psbase.Invoke("Members"))
foreach ($member in $members) {
$name = $member.GetType().InvokeMember("Name", 'GetProperty', $null, $member, $null)
$name
}
}
}
process {
#Sprawdzenie, czy jest możliwe podłączenie się do stacji.
$isComputerReadyForTest = try {
$isConnected = Test-Path -Path "\\$computerName\C$" -ErrorAction SilentlyContinue
$adminMembers = (Get-LocalGroupMembership -Computer $computerName -Group "Administrators")
$rdpMembers = (Get-LocalGroupMembership -Computer $computerName -Group "Remote Desktop Users")
($isConnected -and ($adminMembers -contains "user.2") -or ($rdpMembers -contains "user.2"))
}
catch [System.Management.Automation.MethodInvocationException] {
Write-Warning "cannot test $computerName"
$false
}
$isComputerReadyForTest
}
}
$udCardElements = if (Test-Computer -Computer $computerName) {
$header = New-UDCardHeader -Title $computerName -Avatar $(New-UDAvatar -Content { "T" } -Sx @{ backgroundColor = "#00FF00" })
function Test-LogonSessions {
param (
[Parameter(HelpMessage = "ComputerName to test logonsession", ValueFromPipeline)]
[Alias("Computer")]
[string]$computerName
)
process {
$userFromStationCSV = (quser /server:$computerName 2>&1) -split "\n" -replace '\s{2,}', ','
if ($userFromStationCSV -match "ID") {
$userObjects = $userFromStationCSV | ConvertFrom-Csv -Delimiter ','
foreach ($userObject in $userObjects) {
[PScustomObject]@{
COMPUTERNAME = $computerName
USERNAME = $userObject.USERNAME
TIME = (Get-Date).ToString("dd.MM.yyyy_HH.mm")
ID = $userObject.ID
STATE = $userObject.STATE
}
}
}
else {
[PScustomObject]@{
COMPUTERNAME = $computerName
USERNAME = "BRAK"
TIME = (Get-Date).ToString("dd.MM.yyyy_HH.mm")
}
}
}
}
function Get-IpAddress {
[CmdletBinding()]
param(
[Parameter(HelpMessage = "ComputerName to test IPAddress", ValueFromPipeline)]
[Alias("Computer")]
[string]$computerName
)
process {
$ipAddress = try {
(Get-CimInstance -Query "SELECT IpAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'" -ComputerName $computerName).IpAddress[0];
}
catch {
(Get-WmiObject -Query "SELECT IpAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'" -ComputerName $computerName ).IpAddress[0]
}
$ipAddress
}
}
$udListItemObject = [PSCustomObject]@{
LOGGED = $(Test-LogonSessions -Computer $computerName).USERNAME
IP = $(Get-IpAddress -Computer $computerName).ToString()
TUXEDO = $(((Get-Content -Path "\\$computerName\C$\environment\file.environ" -ErrorAction SilentlyContinue)[4]).Replace(";*", " ").Trim(" ").ToString())
}
$body = New-UDCardBody -Content {
New-UDList -Children {
New-UDListItem -Label 'Logged' -Icon (New-UDIcon -Icon user -Size 1x) -SubTitle $($udListItemObject.LOGGED)
New-UDListItem -Label 'IP' -Icon (New-UDIcon -Icon laptop -Size 1x) -SubTitle $($udListItemObject.IP)
New-UDListItem -Label 'Environment' -Icon (New-UDIcon -Icon leaf -Size 1x) -SubTitle $($udListItemObject.TUXEDO)
}
}
[PSCustomObject]@{
HEADER = $header
BODY = $body
}
}
else {
$header = New-UDCardHeader -Title $computerName -Avatar $(New-UDAvatar -Content { "F" } -Sx @{ backgroundColor = "#FF0000" }) #IDEA: -Subheader można coś tutaj dodać
$body = New-UDCardBody -Content {
New-UDList -Children {
New-UDListItem -Label 'Logged' -Icon (New-UDIcon -Icon user -Size 1x) -SubTitle $($udListItemObject.LOGGED)
New-UDListItem -Label 'IP' -Icon (New-UDIcon -Icon laptop -Size 1x) -SubTitle $($udListItemObject.IP)
New-UDListItem -Label 'Environment' -Icon (New-UDIcon -Icon leaf -Size 1x) -SubTitle $($udListItemObject.TUXEDO)
}
}
[PSCustomObject]@{
HEADER = $header
BODY = $body
}
}
New-UDCard -Header $($udCardElements.HEADER) -Body $($udCardElements.BODY) -Sx @{width = 300; maxWidth = 300; border = '2px solid #f0f2f5' } -Id 'card'
} -AutoRefresh -AutoRefreshInterval $(60 * 5)
}
}
}
Hi I am obviously as green as frog in PowerShell Universal\PowerShell DAshboard\something with dashboard but i need help.
WHAT I WANT TO DO:
I want to do dashboard with all computers in my test env (400) which is readed from txt file.
In that UD Card I want to have:
-Header - computerName
-Avatar - changed dynamicaly every few seconds/few minutes letter and color T(green) or F(red) depends if computer is Test-Connect
-Body- In body i want to have UdList where i want to have:
–UDLabel name Logged changed dynamically depends which user is logged on station with specific icon
–UDLabel name Ip with ip
–UDLabel name Environment changed dynamically which information which environment is on station. The environment check is made every few seconds/minutes.
CONCLUSION
As you see i create that code, but the problem is i do not know how to edit it. Now it works but it is slow, and i want to make it faster. Can someone edit it and explain how and why is edited every piece of code?