Monthly Archives: August 2017

How To: Modify Trusted Hosts to connect via Powershell

We have to connect to untrusted machines via PowerShell. To do this, you have to add the machines,

First, if you have settings in there run this command to get a backup:

$trustedhosts = get-Item -Path WSMan:\localhost\Client\TrustedHosts

Then to get them to modify:

$trustedhosts.value

copy that out, add your hosts to it with comma delimited and add it with powershell:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'Server2,Server2'

To use it in code (so it doesn’t ask you if you’re sure), you can force it by using the -Force switch

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'Server2,Server2' -Force

then check again:

get-Item -Path WSMan:\localhost\Client\TrustedHosts

[Resolved] OnePlus 3 3T Screen Goes Blank or Locked when Dialing Someone

I had a problem last week where my phone started to lock the screen the moment I clicked on dial. It seemed that the proximity sensor on the OnePlus 3T was stuck and it assumed that I had the phone up to my face. I contacted OnePlus about this issue and their solution (As Always) was to reinstall the entire operating system. Basically wipe the phone.

Well, the simple fix is to toggle double tap!

So, to do this, go into your settings and find Gestures. In Gestures, turn off Double Tap. At this point, I rebooted my phone, made a phone call and verified that the problem was gone.

Then I turned on Double Tap again and made another call.

Problem resolved!

PowerShell How To: Find all users where account is inactive

I was recently asked asked to find all the users in Active Directory where their account was inactive.

There is a PowerShell commandlet called Search-ADAccount that you can use to find if the account is inactive by using the parameter -AccountInactive.

This is kind of crude but works well. I couldn’t figure out how to get the headers into the csv so I simply did a write-output for the first section.

#######################
# Ed Rockwell
# Free to use
# Version 1.0
# 8/7/2017
#######################
$time = 90 # Days since last login
$users = Search-ADAccount -AccountInactive -UsersOnly -TimeSpan $time # Get all users within that timeframe with AccountInactive Property greater than $time
$path = "C:\Powershell\AccountInactive" # Where to write file

#File Name
new-item $path\users.csv -Force

# Set the header of csv (Change this if you add to the write-output below)
write-output "$("SamAccountName"),$("Enabled"),$("PasswordExpired"),$("LastLogonDate"),$("OU Location")"  | add-content -path $path"\users.csv"

# Find users 
foreach ($user in $users) 
    {
        If ($user.DistinguishedName -notmatch 'OU=Disabled Users' -and $user.DistinguishedName -notmatch 'OU=Service Accounts' -and $user.DistinguishedName -notmatch 'CN=Microsoft Exchange System Objects')
            {
                $DN = $user.distinguishedname -split ',' 
                $container = $DN[1]
                write-output "$($user.SamAccountName),$($user.Enabled),$($user.PasswordExpired),$($user.LastLogonDate),$($container)" | add-content -path $path"\users.csv"
            }
    }