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.

Review of ‘IT WORKED FOR ME’

Review of IT WORKED FOR ME by Colin Powell with Tony Koltz

The reason I picked up this book, It worked for me, is I remembered, as a teenager, Colin Powell was the Secretary of State under President George W. Bush.  I knew he was a US Army general and that he served under a republican administration.  However, this was all I knew of him.  I was pleased to find out more information about him personally, his career, where he has served and his leadership philosophies. That is what this book brings to the table.

I have some military experience in my life, so the stories he presented and his leadership style was very familiar to me. I caught myself reflecting on my own habits and the practices of my superiors. One of his stories talked about having to get silly military training complete for his unit and complete the mission at hand. This is even more common in today’s military. His philosophy was to get the small tasks done first to move onto the mission and keep his superiors happy while defending our nation.

Reflection:

Diving into that last thought I can think of two responses. Either we need to fix the silly requirements so we don’t need to do them again or comply and move past the frivolous task. I believe it comes down to time and that both of these responses can be accomplished.  If there is time before the mission, project or quarterly plan, leaders should be able to throw up a red flag to fix the larger issue at hand. If we are on a tight schedule then move to complete the task then carry out the mission. Once the dust settles give the feedback to you leaders that the task needs to change.

Don’t forget to add in your recommendation on how to change it for the better.

A couple of other key points from the book: be where you are most effective as a leader. Colin Powell made sure to hire in people that had strengths that would complement his weaknesses. Turn minor corrections into positive learning experiences. I personally enjoy this one, I detest yelling and demeaning in the military without a valid purpose. If you want a drone to follow you, buy one and program it yourself. If you want an effective worker, team member, or soldier treat them like a human with a certain amount of respect.

Wrap up:

The last bit that I really enjoyed was learning about the different administrations Colin Powell served in and the people he met. He talks about his time with Princess Diana, President Reagan and various people of the press. It’s those little insights that help round out the picture for me. Instead of just the former Secretary of State, Colin Powell becomes more personable.  I’m glad I took the time to look back at his experiences and leadership style.

 

The book can be bought here on Amazon:  https://www.amazon.com/Worked-Me-Life-Leadership/dp/0062135139 

Great By Choice Book Review

Great By Choice Book Review

First off, I want to thank ConnectWise for sending me this book, Great By Choice. The company I worked for became a customer of theirs and I was the lead engineer implementing their product. Then ConnectWise saw it fit to send me this book and it was a good read. So thank you to that whole team.

 

Did I enjoy the read? Yes, ‘Great By Choice’ from Jim Collins and Morten Hansen is a summary on a study of 14 companies and answers the question: ‘why did 7 of these companies become great and the others failed?’  Two points that stuck out to me was leaders need fanatic discipline and the ‘20 mile march wins’

 

Discipline is something that I wish I had more of. I can be financially frugal but when it comes to being productive with my side project I can get lazy. Fanatic discipline sets high goals and does whatever necessary to achieve them. It also does not allow the pressures from outside to shift the goals or knock them astray. One new thing I am doing is keeping track of the days that I work on my side project and trying to hit more days worked than not. It gives me a good check in the mirror, ‘am I working at a 10X level?’ Spoiler Alert: I’m not yet, but I hope to reach that level. 

 

‘The 20 mile march’ has some great stories tied to it. I won’t ruin them, I’m also sure the information is out there already, but the stories really bring home the point that you need to be steady with your work. Twenty miles at time, rain or shine, no more and no less. That is what gets you consistency and produces results. I can see this in my own projects as I commit to blogging, working on my side project and other personal or professional goals. Thank you for reading and I hope to post more content soon. 

 

You can find a summary of the book here: https://www.jimcollins.com/books/great-by-choice.html

The book is for sale on Amazon: https://www.amazon.com/Great-Choice-Uncertainty-Luck-Why-Despite/dp/0062120999

ConnectWise is located here: https://www.connectwise.com/