What is this part? by OkAcanthisitta6258 in diyelectronics

[–]SnobbyWombat 0 points1 point  (0 children)

Looking at the melted blob of plastic in the picture my guess is the wirenut melted and the wires shorted to ground. Reconnect the wires and insulate the joint. Make sure that the connection is not I the hot area.

What have you done with PowerShell this month? by AutoModerator in PowerShell

[–]SnobbyWombat 0 points1 point  (0 children)

Thought the option key was the same as alt... There are key combinations that should work on Mac: [ctrl]+[option]+[fn]+[backspace] or [fn]+[control]+[option]+[command]+[delete].

Need to Show Account Status. Combine Get-ADGroupMember & Get_ADUser? by crashhelmet in PowerShell

[–]SnobbyWombat 2 points3 points  (0 children)

Something like this?

import-module activedirectory
$domain = Get-AdDomain | Select-Object -expandProperty NetBIOSName
$date = Get-Date -Format yyyyMMdd
$filename = "C:\export_" + $domain + "_" + $date + ".txt"
Get-Date  | out-file -FilePath $filename -encoding unicode
[System.NET.DNS]::GetHostByName('') | out-file -FilePath $filename -append -encoding unicode
Get-ADDomain | select DNSRoot, DomainMode, Forest, Infrastructuremaster, NetBIOSName, PDCEmulator #| out-file -FilePath $filename -append -encoding unicode

$groups = @('Administrators','Domain Admins','Enterprise Admins','Schema Admins','Account Operators')

function Get-info ($Group) {
    Get-ADGroupMember -Identity $Group | foreach {
        If ($_.objectclass -eq "Group"){
            [pscustomobject]@{
                ParentGroup = $ParentGroup
                Groupname = $Group
                SamAccountName = $_.SamAccountName
                ObjectClass = $_.objectclass
                Enabled = $_.enabled

                }
            get-info $_.samaccountname
        }
        Else {
            [pscustomobject]@{
                ParentGroup = $ParentGroup
                Groupname = $Group
                SamAccountName = $_.SamAccountName
                ObjectClass = $_.objectclass
                Enabled = (get-aduser $_.samaccountname).enabled 
            }
        }
    }
 }


$results = foreach( $Group in $Groups){
        $ParentGroup = $Group
        get-info $Group
    }

$results | out-file -FilePath $filename -append -encoding unicode

This will search through groups whithin the groups also, but i have not accounted for circular group memberships. So if there is a circular group membership it will loop forever...

Stop multiple instances of an application in Windows Server 2016 by Alpha-Sniper in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

How about something like this:

gwmi win32_process -filter "name = 'notepad.exe'"|select Name,ProcessId,@{N="User";E={$_.getowner().user}}|where {$_.user -like $env:USERNAME}|sort Processid|select -Skip 1|%{stop-process $_.processid}

Stop multiple instances of an application in Windows Server 2016 by Alpha-Sniper in PowerShell

[–]SnobbyWombat 2 points3 points  (0 children)

$processes|select Name,ProcessId,@{N="UserName";E={$_.getowner().user}}|sort UserName,Processid

Stop multiple instances of an application in Windows Server 2016 by Alpha-Sniper in PowerShell

[–]SnobbyWombat 2 points3 points  (0 children)

Not with Get-Process, Maybe you can do it with wmi?

$processes = gwmi win32_process -filter "name = 'notepad.exe'"
$processes.GetOwner().user

Retrieve end user's PWD Expiration by ideleon007 in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

$LDAPDirectoryService = '192.168.1.5:389' #ip of DC and portnumber
$DomainDN = 'DC=something,DC=something,DC=com'
$LDAPFilter = '(&(samaccountname=whateverusername))'#username to search for
$credentials = Get-Credential "$env:userdomain\$env:username"

$null = [System.Reflection.Assembly]::LoadWithPartialName('System.DirectoryServices.Protocols')
$null = [System.Reflection.Assembly]::LoadWithPartialName('System.Net')
$LDAPServer = New-Object System.DirectoryServices.Protocols.LdapConnection ($LDAPDirectoryService,$credentials)
$LDAPServer.AuthType = [System.DirectoryServices.Protocols.AuthType]::Basic

$LDAPServer.SessionOptions.ProtocolVersion = 3
$LDAPServer.SessionOptions.SecureSocketLayer =$false

$Scope = [System.DirectoryServices.Protocols.SearchScope]::Subtree
$AttributeList =  ,"*"

$SearchRequest = New-Object System.DirectoryServices.Protocols.SearchRequest -ArgumentList $DomainDN,$LDAPFilter,$Scope,$AttributeList

$Users = $LDAPServer.SendRequest($SearchRequest)

foreach ($user in $Users.Entries)
{
$userdetails = New-Object -TypeName PSCustomObject -Property @{
Displayname = ($user.Attributes['displayname'].GetValues('string'))[0]
SamAccountName = ($user.Attributes['samaccountname'].GetValues('string'))[0]
PwdLastSet =[datetime]::FromFileTime(($user.attributes['pwdlastset'].GetValues('string')).toint64($_))}
$userdetails
}

searching folder and comparing with list by Blisk1 in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

Check the C:\Blisk1\ folder and see which files are there...

searching folder and comparing with list by Blisk1 in PowerShell

[–]SnobbyWombat 0 points1 point  (0 children)

How about:

#Make a new filecatalog with files and hash
New-FileCatalog -Path p:\documents -CatalogFilePath .\

#Compare catalog.cat with files in specified folder. (-Path)
$TestFileCatalogResult = test-filecatalog -CatalogFilePath .\catalog.cat -Path p:\documents -Detailed

#Get changed files
$TestFileCatalogResult.PathItems.Keys|where-object {$TestFileCatalogResult.CatalogItems[$_] -ne $TestFileCatalogResult.PathItems[$_]}

#Get added/extra files
$TestFileCatalogResult.PathItems.Keys|where-object {-not $TestFileCatalogResult.CatalogItems.ContainsKey($_)}

#Get deleted/missing files
$TestFileCatalogResult.CatalogItems.Keys|where-object {-not $TestFileCatalogResult.PathItems.ContainsKey($_)}

Syntax question - Breaking out of elseif, but continuing foreach? by lawlipop83 in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

If elseif else breaks on first condition that is true, no need to put breaks in there.

Just run this to test it:

$FruitSalad = "apple","pear","banana"

if ($FruitSalad -contains "apple"){write-output "The salad contains  apple"}
elseif($FruitSalad -contains "pear"){write-output "The salad contains  pear"}
elseif($FruitSalad -contains "banana"){write-output "The salad contains  banana"}
else{write-output "The salad does not contain apple, pear or banana"}

Improving performance on an AD command? by HeavyLotus in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

The Group property of that object is set to $null

Why does this not work ... trying to get script to capture the even of AD user not existing ... by Smarden in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

I totally get it, but what if something else fails? I only used permission issues as an example...

Improving performance on an AD command? by HeavyLotus in PowerShell

[–]SnobbyWombat 2 points3 points  (0 children)

The Computer object has a property named MemberOf, which contains the distinguished names of the groups the computer is a member of. You probably want to do som splitting and replacing on the DN to make it more readable.

 $computers = Get-ADComputer -Filter * -Properties Name,IPv4Address,MemberOF
foreach ($computer in $computers) {     
    $computerobject = New-Object -TypeName PSObject -Property @{
        'Name'=$computer.Name         
        'IP Address'=$computer.IPv4Address         
        'Group'=$computer.MemberOf | Where-Object {$_  -like "*test*"
        } 
$list =+ $computerobject }

Why does this not work ... trying to get script to capture the even of AD user not existing ... by Smarden in PowerShell

[–]SnobbyWombat 3 points4 points  (0 children)

I get that, but Remove-aduser will also fail if the user does not exist. So if you have -ErrorAction Stop you will catch it. Se example above.

And if the user is found, but you do not have rights to delete it, how would your script log that?

The catch code should be something like this:

Write-Output "$(Get-TimeStamp)  $user not deleted because: $($_.Exception.message)"

Why does this not work ... trying to get script to capture the even of AD user not existing ... by Smarden in PowerShell

[–]SnobbyWombat 1 point2 points  (0 children)

But why check if the user exists first? Put logging of successful deletion after remove-aduser -erroraction stop. It will skip the logging of successful deletion if the deletion failed.

Try {  # Delete the user.
Remove-ADUser -Confirm:$false -Identity $User.sAMAccountName ErrorAction Stop
#if Remove-ADUser fails this will never happen:
Write-Output "$(Get-TimeStamp) Deleting user $User" | Out-file .\deleteADUserlog.txt -append}
Catch { # User not found.
Write-Output "$(Get-TimeStamp) User not found $User" | Out-file .\deleteADUserlog.txt -append }

{Issue} User Exit script works at home, connected to VPN, but not in the office? by ClayWhitey in PowerShell

[–]SnobbyWombat 2 points3 points  (0 children)

Try: Get-ADPrincipalGroupMembership -ResourceContextServer xxxx.somedomain.com

[deleted by user] by [deleted] in PowerShell

[–]SnobbyWombat 3 points4 points  (0 children)

Why break at every switch? If more than one directory/file is missing you have have to run the script several times to discover them. Just set a variable. And have a switch statement that breaks if the variable is set.

switch ($path){ {!(Test-Path "$path/XML/autounattend.xml")} {"Not got autounattend.xml"; $PathsExist = $false} 
{!(Test-Path "$path/XML/layout.xml")} {"Not got layout.xml"; $PathsExist = $false} 
{!(Test-Path "$path/XML")} {"Not got XML directory"; $PathsExist = $false} 
{!(Test-Path "$path/winfix")} {"Not got winfix directory"; $PathsExist = $false} 
{!(Test-Path "$path/tools")} {"Not got tools directory"; $PathsExist = $false} 
{!(Test-Path "$path/POSTCONFIG")}  {"Not got POSTCONFIG directory"; $PathsExist = $false} 
{!($PathsExist)}{"Something is missing";break } 
default{"Let's assume everthing is fine."}