Uncategorized

PowerShell to Manage thumbnail Cache databases used by file Explorer

So I have seen some issues with thumbnails in 1809 Enterprise edition.

When I am aggravated with them I clip them. it’s just good hygiene. lol

 

so here is a telltale script that does just that.

<#
Thumbnail Issue
-kill explorer tasks
-Remove Thumbnail databases
-restart explorer

#>


#-kill explorer tasks
write-host "stopping the Explorer Process."
Stop-Process -Name explorer -Force

#-Remove Thumbnail databases

Write-Host "These files need to be removed to ensure that they are not Corrupted:" -ForegroundColor Yellow
Get-ChildItem -Path "$env:LOCALAPPDATA\Microsoft\Windows\Explorer\" thumbcache_* | select -ExpandProperty fullname -OutVariable THUMBS

remove-item $THUMBS -Force  -ErrorAction SilentlyContinue -ErrorVariable ThumbErrors

new-item c:\ -name Logs -ItemType Directory -ErrorAction Stop; $THUMBS| Export-Csv THumbDBErrorLog.csv -NoTypeInformation

That is how you clip those unsightly thumbnails….

Functions, Scripting Technique, Uncategorized

User Back up function or Script

 

First I want to point out the $home variable for individual self initiated back ups.

so if you wanted to back up specifics to the current logged in user $home is Sufficient, even if you have DFS / or SMB redirected home folders.

if you are backing up all users you need to also save the sticky notes. that’s an added bonus to reading my article.

Function Get-Backup ($user){

# Get logged on Username
if ($User -like $null) {$User = $env:username}

Create path using variables so that we arent guessing usernames.
$path = "\\Server\Users\$user\user_backup\$(Get-Date -Format M)\"

#create newer Path based on the date.
new-item -ItemType directory -Path $path -ErrorAction SilentlyContinue
$logged ="$path\Results.txt"

#copy contents of vital folders specified below from there paths to the new location.

copy-item c:\users\$user\pictures -recurse -Destination $path -ErrorAction SilentlyContinue
copy-item c:\users\$user\documents -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\downloads -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\favorites -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\links -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\desktop -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\music -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
copy-item c:\users\$user\contacts -recurse -Destination $path -Verbose -ErrorAction SilentlyContinue
# I only included these folders because these are standard folders anything extra needs to be added manually.

I know a lot of people who are attached to their sticky notes.
located here:
$notes= ls "C:\Program Files\WindowsApps\microsoftstickynotes*"
copy-item $notes.fullname $path -Verbose -ErrorAction SilentlyContinue
}#End Function  you can always make this much more robust.

 

Enjoy City Life? I grew up in the city and I rather not deal with heavily populated areas. although I prefer people than bugs that goes for computer bugs too lol

Uncategorized

AWS/GoogleCloud and harnessing PowerShell (One Shell to rule them all)

Heads up….. The cloud is ready.

There is alot of fun to be had with different Platforms and PowerShell grew up on the mean streets of scrutiny, much like myslef and we are much alike in our flexibility to adapt and automate anything, although I am sure PowerShell probably doesn’t need me as much as I rely on it’s abilities to be context sensitive to my tab key.

Looking at the featured image i used for the article it is clear to see a lot of platforms have embraced PowerShell with a favorable amount of cmdlets. JUST THINK OF THE AUTOMATION POSSIBILITIES!

Okay, so to warn you ahead of time, I maybe diving into all the cloud crowds shortly to give myself an expanse of elbow room when scripting solutions.

Stay informed and do not forget to Get-Help!

This is for amazon webservices:

Install-Module -Name AWSPowerShell

This is for GoogleCloud:

find-module -Name googlecloud | install-module 

This may may only possible after you enable and trust the repositories.

Take Care Citizen!

Scripting Technique, Uncategorized

Using a series of numbers to loop through an object or process.

I wanted to share this to help people that have to build scripts that parse/writes tons of files.

I always use the numbers depending on scale like the following.

1..17 | |foreach-object {Write-Output "User$_"}

another example if you need files:

$objectarray=@()

1..17 | |foreach-object {new-object psobject  -property @{ name="User$_"}


Well depending on the task you can create a dev variable of sorts. to contain your creation of variables is sound and effective.

I wouldn’t rely on it in a production script unless you did a “foreach($this in $that)” scenario.

chime in if you have any questions or request. I welcome a challenge.

Scripting Technique, server, Uncategorized

Learning when and “Where”.

learning your way around the shell is really important. the “where-Object” is like the GPS of the pipeline and to elaborate on the pipeline a little is a one way train to get you to the solution you need.

here is an example.

where GPS

I set this to select the first one to help trim the image. There are 3 properties to navigate these service entries.

I used the pipeline to give you an example of the “|” pipeline so you can understand the flow of things. the object(s) are declared and sometimes processed before the pipeline. then more things can happen.

Look below for an example:

Where Turn by Turn.jpg

The pipeline is the directions in which you mold your data.  you put that with some select-object & other commands like format-list, ConvertTo-html, Export-csv, & Out-File.

So I can’t wait to see what you have waiting to travel down the pipeline! See you around the city!

Functions, Scripting Technique, Uncategorized

PowerShell Get-TimeMachine?!

Well, I know what you’re thinking, it is just click bait. But I want to assure you it is possible.

new-timespanYou could create this into a function but the magic is in the details of this one.

“New-TimeSpan” is a tool that has existed since 2.0 and before you start-sleep ever again, consider the possibilities if you can truly calculate the duration of start-sleep dynamically!

So I stumbled across this only due to the need to simulate a scheduled task/job quickly in an environment I had not the local privileges to ensure that I could create a scheduled job.

If necessary you could utilize this to create some uniformity in your daily duties, reminders, etc.

 

So Let’s see this tag team with Start-Sleep!

tagteam timespan

I included the variable to display how this works so well. you just define when you want the script to stop that same day. It will show an error if you did it differently.  However, as long as the values are a positive number and not a negative integer you have a timespan.

The last example is using it to control things in the future….essentially a PowerShell Time machine, please share any of your experiences in the comments or on Twitter.

timemachine

so just know that time only flows in one direction. Trying to relive the past can cause you errors lol. Kind of ironic how that works outside the shell too. Don’t forget to visit other parts of the city. See ya around, and avoid cyclic redundancy errors!

Functions, Scripting Technique, Uncategorized

Writing Functions in PowerShell

functioning like an adult

I would like to propose we should all function as adults at some point in life. maybe not 24 hours a day but enough to take care of ourselves.

PowerShell is an area that need you to be functioning to preserve your sanity and time, I will cover simple & advanced functions.

A function can save you a ton of typing and it could do quite a bit and be called using the infamous tab completion!

Simple Function Example:

Function Test-Google
{
Try{ $result=Test-Connection google.com
if ($result -ne $null){ write-host "Google is up and reachable" -ForegroundColor Green} 
}
Catch{write-host "Google Error Occured" -ForegroundColor Red}

}

 

Advanced Function Example:

Function Test-NetworkConnectivity
{
[cmdletbinding()]
param(
[parameter(ValueFromPipelineByPropertyName,ValueFromPipeline)][Object[]]$Website =@( "google.com","Bing.com")
)
Begin{}

Process{
FOREACH($SITE IN $Website)
{
Try{ $result=Test-Connection -ComputerName $site
if ($result -ne $null){ write-host "$site is up and reachable" -ForegroundColor Green} 
}
Catch{write-host "$site Error Occured" -ForegroundColor Red}
}
}
}

Take the time to explore tab completion.  this advanced function has way more capability and any questions?

 

 

Scripting Technique, Uncategorized

Troubleshooting Desktop Issues with Get-Eventlog

in the event you need to check your computer events to track down issues with your machine I must implore you to use “get-EventLog”

 

use this to your advantage to pinpoint issues.

 

in the image I used :

Get-EventLog -LogName system -Newest 1 -EntryType Error | Format-List

 

mainly to for word wrap and readability you can also automate this and dump to a report or email every so often.

 

 

Scripting Technique, Uncategorized

Audit Objects in your Domain(s) using switch statements in PowerShell

I find it important to figure out who and what is in your active directory OUs

get-aduser $TargetedUser

What about groups, and computers?

get-adobject $targetObject

this includes users, groups, and computers.

here is a switch that will report differently based on object class property that gets returned.

get-adobject -filter *| foreach-object{
Switch($_.Objectclass) {

User{ write-host "Found a User" -foregroundcolor red
      $_ | export-csv Users.csv -notypeinformation -append
     } #end User

Group{ write-host "Found a Group" -foregroundcolor blue
       $_ | export-csv Group.csv -notypeinformation -append
     } #end group

Computer{ write-host "Found a Computer" -foregroundcolor cyan
          $_ | export-csv Computers.csv -notypeinformation -append
     }#end Computer
}#end switch

}#end Foreach-object from pipeline