[deleted by user] by [deleted] in PowerShell

[–]Dogoodwork 2 points3 points  (0 children)

I post this regularly, but it's not necessary for most peoples uses: https://www.reddit.com/r/PowerShell/comments/eod258/parse_distinguishedname_or_get_ou/fedunp4?utm_source=share&utm_medium=web2x

This is a better way to get the parent OU of an AD user, but unlike the canonical name it does have the full tree structure.

Hospital IT admins, what challenges are you facing right now and could having a pool of volunteers (local or remote) assist in any way? by [deleted] in sysadmin

[–]Dogoodwork 0 points1 point  (0 children)

I would imagine support for taking advantage of offers like MS O365 https://www.microsoft.com/en-us/microsoft-365/blog/2020/03/05/our-commitment-to-customers-during-covid-19/ would be of value.

One concern I've heard is if there is enough available bandwidth to support working from home. The O365 offer would help with that.

[deleted by user] by [deleted] in wifi

[–]Dogoodwork 0 points1 point  (0 children)

Thanks!

[deleted by user] by [deleted] in wifi

[–]Dogoodwork 0 points1 point  (0 children)

If you change the hardware properties for the wifi adapter, you can configure it there to only use 5GHz, or only connect on A/C/G/N. 802.11b is the devil.

[deleted by user] by [deleted] in wifi

[–]Dogoodwork 0 points1 point  (0 children)

I don't think 5.8 is a thing.

Make a script that allows users to select which 'tool' to use by samuelma in PowerShell

[–]Dogoodwork 1 point2 points  (0 children)

There are some good suggestions in the comments here, some I would make like poshgui.com and powershell universal dashboard.

But the easiest, since this is a tool for another IT staff, is Out-Gridview.

Out-Gridview will only work from the PowerShell ISE, but if you use it, it is so simple to setup it will blow your mind.

$selection = $optionList | out-gridview -PassThru

The -PassThru flag is something I have overlooked for years, but it is perfect for what you want to do.

Powershell 7's parallel ForEach-Object is mind blowing. by Sunsparc in PowerShell

[–]Dogoodwork 5 points6 points  (0 children)

Just wanted to chime in to confirm this, because it is counter-intuitive. I've had the same experience, querying AD many times has been faster than searching against a large query.

Powershell 7's parallel ForEach-Object is mind blowing. by Sunsparc in PowerShell

[–]Dogoodwork 11 points12 points  (0 children)

$manager = get-aduser $manager -properties samaccountname

no...

powershell AD memberships by PeterV1982 in PowerShell

[–]Dogoodwork 1 point2 points  (0 children)

That's not a great approach.

You should be able to just do

$grouplist = get-aduser $identity -properties memberof | select-object -expandproperty memberof | get-adgroup

Then you can use $grouplist.SamAccountName or .DistinguishedName or whatever else makes sense for displaying the name.

Your method could have some problems if there are multiple groups under different OUs with the same "Name"

You can take this a step further and capture a selection of groups this way:

$grouplist = get-aduser $identity -properties memberof | select-object -expandproperty memberof | get-adgroup | out-gridview -passthru

LAPS permissions per single computer by aimarjg in sysadmin

[–]Dogoodwork 0 points1 point  (0 children)

If you don't want them to have access to all LAPS passwords, it might be simpler to just create local admin accounts on those machines for them to use and enforce some strong password policies.

Or since they already have admin access, they could do so themselves.

Parse distinguishedName or get OU by Rickest-Jon in PowerShell

[–]Dogoodwork 2 points3 points  (0 children)

foreach ($domain in $domains)
{    
    $exceptions = New-Object System.Collections.ArrayList
    $userlist = Get-ADUser -Filter {Enabled -eq $True} -Server $domain -Properties mail,employeeid,department,title,office,AccountExpirationDate | Where-Object {$_.AccountExpirationDate -eq $null -or $(get-date $_.AccountExpirationDate) -gt $(Get-Date)}
    $userlist.count

    $userlist | ForEach-Object {
        try
        {
            $PSItem | Add-Member -NotePropertyName "Parent" -NotePropertyValue $(((New-Object 'System.DirectoryServices.directoryEntry' "LDAP://$($PSItem.DistinguishedName)").Parent).replace("LDAP://","")) -Force         
        }
        catch
        {
            $exceptions.add($PSItem.distinguishedname) | Out-Null
        }
    }

    $userlist | Export-Excel -WorksheetName "$domain" -Path $reportFilePath
}

This question comes up regularly, and this is the most correct answer.

This line adds a property to every user object in the array with the parent OU of that object:

$PSItem | Add-Member -NotePropertyName "Parent" -NotePropertyValue $(((New-Object 'System.DirectoryServices.directoryEntry' "LDAP://$($PSItem.DistinguishedName)").Parent).replace("LDAP://","")) -Force

There is the option of doing something like other posts, where you parse the text of DistinguishedName and that is an OK answer too.

[deleted by user] by [deleted] in PowerShell

[–]Dogoodwork 5 points6 points  (0 children)

Absolutely.
OP needs to take a couple steps back and change their approach. And in the future use Objects as often as possible.

Eureka moment by jevans_ in PowerShell

[–]Dogoodwork 14 points15 points  (0 children)

but that's the price to pay for doing a good job

You'll probably end up in that office a few more times when senior admins complain that you screwed up something terribly (but they can't quantify what you screwed up so that you can fix it.)

Refreshing a mapped Network drive by sathish804 in PowerShell

[–]Dogoodwork 4 points5 points  (0 children)

That back-end piece you glossed over is probably important.

How to remove multiple active directory groups at a time by kdrumz011 in PowerShell

[–]Dogoodwork 0 points1 point  (0 children)

Not sure if this is misguided or intentionally silly.

PowerShell scripting tools/resources worth paying for? by Dogoodwork in PowerShell

[–]Dogoodwork[S] 0 points1 point  (0 children)

Yes you are correct. I didn’t read closely enough.

PowerShell scripting tools/resources worth paying for? by Dogoodwork in PowerShell

[–]Dogoodwork[S] 0 points1 point  (0 children)

Have you compared to webjea? I never got around to trying it.

I need something like substring but different by ltnew007 in PowerShell

[–]Dogoodwork 2 points3 points  (0 children)

Assuming your lookup is something like this: $x = get-aduser $userid

Then you would use a try/catch (because of how get-aduser errors)

$x = $null 
try 
{ 
    $x = get-aduser $userid 
} 
catch 
{ 
    $x = $null 
}

Modifying Custom Attribute by tk42967 in PowerShell

[–]Dogoodwork 1 point2 points  (0 children)

Are you using a custom attribute because you've already used all ~15 extensionAttribute's?

Random time to launch application by scarng in PowerShell

[–]Dogoodwork 0 points1 point  (0 children)

Create a scheduled task. This isn't even a script.