Create Restart Program Batch Script

This week I was playing around with a new setup, multiple computers and multiple monitors. I tried to use a program called mouse ShareMouse… and it worked great. However the free version causes you to buy or restart the program every 30 min or so to use the ‘pro’ features. That’s when I thought to just create a restart program script just to see if it would work. 

I decided to use batch to script the restart for ShareMouse. I would need to use a loop, timeout, taskkill and start. First I stopped the service when the script started to ensure the loop didn’t fail if the program was already running. 

@echo off
title SharedMouse Restart Script

taskkill /F /IM ShareMouse.exe

Then you enter the loop. I start the program, wait an amount of time less than the program pro version timeout and stop ShareMouse. 

:loop
echo Starting Application
start "" "C:\Program Files (x86)\ShareMouse\ShareMouse.exe"
timeout /t 300
echo Stopping Application
taskkill /F /IM ShareMouse.exe
goto loop

I ran this script on every computer with ShareMouse and it worked fine. I went all day without hiccup. Just thought I’d share this simple restart program script. 

If you want to get ShareMouse you can find it here

Check out my last scripting post here.

Review of ‘Ownership Thinking’

Review of Ownership Thinking: How to End Entitlement and Create a Culture of Accountability, Purpose, and Profit by Brad Hams

As I read Ownership Thinking, I couldn’t help but think of some consistent concepts that keep getting repeated: open communication, including others and listening to their opinions, entitlements are the worst and it all boils down to revenue. This book, and presumably the late Brad’s consulting group, tells leaders that in order to get their team members to bring in more revenue, leaders must include the team more on how they and the company  can improve. I took away a few great concepts I want share below.

Quick Concepts

People prefer accountability. This rings true to me on a deep level. I know that I need to be working towards something, I need a goal. Reading Ownership Thinking reiterates that I need myself and anyone I work with to consider the big picture from time to time and think of ways to improve. I then suggest the improvements to the team and move forward with a plan. Second, the best incentive plans are self funding. I want to reward myself and others, but not at the expense of everyone on the team. Self funding makes sense in my mind, work hard, get rewarded. If you or the team fall short, then no reward. Third, I need to take an entry-level accounting class. Quite frankly, the profit and loss statements and revenue charts are above my head right now and that is an area that I can improve in. Just add that to the list.

Overall, I recommend Ownership Thinking.  I was sad to learn that Brad had passed away but I’m thankful he embellished this book with his wisdom. The last piece I’ll end with is the ‘Adult Contract’. Expanding just a bit, ‘Adults don’t argue with reality’. Adults learn what they can, listen and make a decision. When you recognize you can improve in an area take the steps to make it happen.  Thank you Brad for writing Ownership Thinking.

You can purchase the book here from the book’s website: http://www.ownershipthinking.com/bradsbook.html

Check out my previous book review here.

gpupdate and RDP with PowerShell

How to gpudate and RDP with PowerShell

In my first PowerShell post, I described running into the issue of maintaining a network where you do not have all admin permissions. A second issue that I ran into was how to gpupdate and RDP with PowerShell.  Updates were pushed out from group policy but machines were not pulling them and staying up to date. How I forced gpupdate was a lot like how I forced remote reboots with PowerShell.

for($i=0; $i -lt $WorkstationArray.Count; $i++){
     $temp = $WorkstationArray[$i]
     Write-Output "Initiate gpupdate for: " $temp
     Invoke-GPUpdate -Computer $temp
}

Loop through an array and RDP into machines

While looping through an array of the workstations it was possible that some of them would be disconnected from the network. I added code to allow me to log any workstation that I could not RDP into. I also added code to save my username and password, but you could make that more secure and not save that in your script.

$LogFile = "C:\workstation_unreachables.txt"
$User="XXXXXXXXXXXXXXX"
$Password="XXXXXXXXXXXXXXX"

Function Logfile{
    Param ([string]$logstring)
    Add-content $LogFile -value $logstring
}

for($i=0; $i -lt $ServerArray.Count; $i++){ 
    cmdkey /generic:"$Templogin" /U:$User /pass:$Password
    $temp = $ServerArray[$i] mstsc /v:"$temp" /admin 
    $log = Read-Host -Prompt "Press y to log this computer name
                   Press any other key to continue"
    if ($log -match "y"){
        LogFile "$temp"
    }
}

Run PowerShell as admin

The last item I had to do was run the PowerShell script as an administrator.  I decided to make a batch script for that. This prompted me for admin credentials whenever it was ran.

@ECHO OFF 

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\gpupdate.ps1""' -Verb RunAs}"

:END
pause

I hope this helps with your admin tasks on your network. If you missed my first post you can read more here. Thank you – Powersjo

How to loop through AD objects with PowerShell

How to Loop through AD objects with PowerShell

While at work, I came across the problem of ‘You don’t own the network but you must deploy and administer the network’. That’s when I had the idea to employ PowerShell scripts and Batch files. When you are given tier 2 admin access to only a particular OU and not full admin access to the whole domain, these scripts might help you ensure your workstations stay up to date. How did I loop through AD objects with PowerShell?

Grab list from Active Directory

In order to loop through multiple active directory objects, I made the choice to grab all the objects in an OU and put them in a text file. To do this I ran a simple windows command in a batch file. Use the command ‘DSQUERY COMPUTER’.
For each OU, start at the top level OU and dive into the final OU.
For the Domain Controller (DC), start at your top level domain (example: blog) eventually diving into the overall domain (example: com, mil, org, us, etc…)

@echo off

DSQUERY COMPUTER "OU=TOPLEVEL,OU=MIDLEVEL,OU=LOWERLEVEL,OU=FINALLEVEL,DC=BLOG,DC=POWERSJO,DC=COM" -o rdn -limit 1000 > c:\objects.txt

pause

Using an array in PowerShell

$WorkstationArray =
''number1'', “number2”, “number3”

In the array put the list of objects from the batch file. I did this manually but I’m sure there is a way to automate it.

Loop through an array in PowerShell

for($i=0; $i -lt $WorkstationArray.Count; $i++){
$temp = $WorkstationArray[$i]
Write-Output "Initiate reboot for: " $temp
Restart-Computer -ComputerName $temp -Force
}

In the above loop I reference each workstation and initiate a restart of each one. If you use ‘-Force’, even when a user is logged in the workstation will restart.

In the next blog post I will post my method of running ‘gpupdate’, initiating RDP and running the PowerShell scripts as an administrator with batch files.

Review of ‘Smart Money Smart Kids’

Review of Smart Money Smart Kids by Dave Ramsey and Rachel Cruze

What is just as important as personally being smart with money? Why it’s teaching your kids to be smart with money. What good is being able to bless your kids if they live in your basement while in their 20’s and 30’s? That is what this book is about. Smart Money Smart Kids shows how to raise money smart kids in a world where rampant debt is normal.

The first part of the book brings home some common sense money and parenting truths.  Money comes from work, the kids will learn from your example and have grace with your kids. As I read through the stories I thought “This is too simple.” Of course money comes from work and everyone knows kids learn by example. Then I realized that saying is one thing, doing is another. Moreover, how can I live a model of being money smart and teach that to my kids?

Next, the book rolls into practicing the principles with your kids. The authors assume you are already good with money and work on a budget. It showcases a mini-envelope system that kids can learn from. Saving, spending and giving. With these three foundations, kids can learn to be wise with the money they have.

Reflection:

I’ve heard Dave Ramsey say before that “The Ramsey’s will never borrow money.” What an audacious pair it takes to say that. Not just for Dave and his wife but his kids as well. That is reflected in this book. First no car debt, second no college debt and third no wedding debt or any other kind of monetary obligation. The book dives into multiple options on how to stay debt free with your children.

“The Powersjo family will never borrow money.” As I meditate on this I realize it’s only possible to keep a family debt free with planning and intentional money management. Summarizing, it’s up to me and my wife to teach them. Of course, I highly recommend the book. It’s an easy read, makes sense and gives parents plenty of tools to teach their kids to be wise with money.

People can purchase this book here on the official website:  https://www.smartmoneysmartkids.com/

You can read my previous book review here.