Net Accounts

I’m trying to figure out the best way to be able to extract info from ‘net accounts’ so that I can parse the info contained in order to validate the values for a remediation task in SCCM. This is what I have so far:

It’s ugly but I think it turns the output into objects that I should be able to work with. I would prefer to turn this output into 8 individual scripts to better control the SCCM remediation tasks.

Am I reinventing the wheel here? Is there a better way to go about extracting this info?

Hey Bill,
You could use ConvertFrom-String

$accountSettings = net.exe accounts | ForEach-Object {ConvertFrom-String -InputObject $_ -Delimiter ": +" -PropertyNames Setting, Value}

Write-host '$accountSettings | Out-Host' -ForegroundColor Cyan
$accountSettings | Out-Host

Write-host '$accountSettings | Where-Object {$_.Setting -eq "Maximum password age (days)"} | Out-Host' -ForegroundColor Cyan
$accountSettings | Where-Object {$_.Setting -eq "Maximum password age (days)"} | Out-Host

Write-host '$accountSettings | Where-Object {$_.Setting -eq "Lockout threshold"} | Out-Host' -ForegroundColor Cyan
$accountSettings | Where-Object {$_.Setting -eq "Lockout threshold"} | Out-Host

Thanks for the reply Curtis! Actually I had just discovered ConvertFrom-String over the weekend and was working with saving the info as an array but I went a completely different route, using secedit to extract some of this info too. I was then using compare to get a diff of two sets of policies and trying to get some output from that. Starting to think I’m just doing it the hard way :slight_smile: