I am working on a web controller to display and (ultimately) modify domain information for users. Ideally I want userName, full name, status (locked?) and whether they are logged in.
I have gotten this far
# Define the target domain controller
$domainController = "myController"
# Hardcoded credentials (for demonstration purposes only, not recommended in production)
$username = "[email protected]"
$password = ConvertTo-SecureString "MyP@ssw03d!*" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
# Connect to the specified domain controller remotely using hardcoded credentials
$sessionQuery = Get-WmiObject -Class Win32_LogonSession -ComputerName $domainController -Credential $credential
$sessionQuery | ForEach-Object {
Write-Host $_.Properties | ForEach-Object {
$propertyData=[System.Management.PropertyData]$_
Write-Host $($propertyData.Name) $($propertyData.Value)
Write-Host "----------------------"
}
}
But the only data it returns from Powershell is System.Management.PropertyData repeated over and over. Not even the divider is being printed.
I am completely unfamiliar with PowerShell scripting but I haven’t been able to find a way to managed this through C#. I am looking for either a solution to this script OR a reference on retrieving what I need from within C#.
Thank you.