Today I've spent some time and wrote a blog post about new features of PSWriteHTML. While it says in the title Advanced HTML reporting it's actually advanced in terms of what you can achieve, but not complicated to use.
There are also heavy improvements in terms of performance where you're now able to store 50k-100k records in a single HTML file and still have responsive HTML.
This scans the whole forest and all GPO's and searches for Authenticated users or Domain Computers permission missing from GPO's. It only does the scan, I didn't want to fix it. Not today at least.
All you will need to do is Add the below code to the beginning of your script It great and comes in handy when you have scripts that need to be run as local admin
NOTE: Tron now has it's own subreddit. Check it out at /r/TronScript
Background
Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually and decided to just script the whole thing. I hope this helps other techs and admins.
De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; Metro debloat (Win8/8.1/2012 only)
Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates
Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD
Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)
+ tron.bat:annoyance: Add annoying disclaimer warning screen (sorry :-/). Accept with -e flag, or change associated EULA_ACCEPTED variable to yes to permanently accept
+ stage_0_prep:feature: Add ProcessKiller utility. Nukes various userspace processes before starting. Thanks to/u/cuddlychops06
+ stage_0_prep:feature: Add speak ability. Tron now audibly announces when it starts and finishes. Mute with the -q flag or the SHUT_UP variable. Depending on interest, may add ability to announce each stage as it begins and completes
+ stage_0_prep:utility: Add nircmd.exe to support speak ability, among other things
! stage_0_prep:bugfix: Fix logic error where we skipped calculating free hard drive space if the system drive was an SSD. Now detect free space regardless of disk type
- stage_4_patch:cleanup: Remove all version-specific subfolders for Java, Flash, Reader, and Notepad++, and rename all .bat installers to be version-neutral. Should reduce number of places we need to update when a new version is released
! misc:bugfix: tons of bugfixes, including MANY affecting Vista. Read the full changelog if you're interested in seeing what they were
Download
Three download options:
Primary: Mirror the BT Sync repo (get fixes/updates immediately) using the read-only key:
BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47
Make sure the settings for your Sync folder look like this (or this on the v1.3.x version).
Download a self-extracting .exe pack from one of the mirrors:
If you want to preview the latest code, the master script is available **[here on Github](https://github.com/vocatus/tron/blob/master/tron.bat)** (Note: this is *only* the script and doesn't include the utilities Tron relies on to function).
Command-Line Support
Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.
Usage: tron.bat [-a -c -d -e -m -o -p -r -s -v -x] | [-h]
Optional flags (can be combined):
-a Automatic mode (no welcome screen or prompts; implies -e)
-c Config dump (display current config. Can be used with other
flags to see what WOULD happen, but script will never execute
if this flag is used)
-d Dry run (run through script without executing any jobs)
-e Accept EULA (suppress display of disclaimer warning screen)
-m Preserve default Metro apps (don't remove them)
-o Power off after running (overrides -r)
-p Preserve power settings (don't reset power settings to default)
-r Reboot automatically (auto-reboot 30 seconds after completion)
-s Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
-v Verbose. Show as much output as possible. NOTE: Significantly slower!
-x Self-destruct. Tron deletes itself after running and leaves logs intact
Misc flags (must be used alone):
-h Display this help text
Integrity
checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.
Please suggest modifications and fixes; community input is helpful and appreciated.
Microsoft has now disabled basic auth for Office 365, with the minor exception of SMTP. While SMTP Basic Auth is not going away because of mostly legacy devices or applications, it's better to switch to oAuth 2.0 and Graph API as per Microsoft's recommendation.
Over one year ago, I wrote a PowerShell module called Mailozaurr, which simplifies sending emails with SMTP using BASIC Authentication, OAuth 2.0 and Graph API, or even SendGrid API. Last week I added functionality to send a that big attachment with Graph.
As Microsoft just disabled basic auth, I thought it would be a good idea to write a new blog post on how easy it is to replace Send-MailMessage with Send-EmailMessaage (part of the Mailozaurr module).
$Credential = ConvertTo-GraphCredential -ClientID $ClientID -ClientSecret $ClientSecret -DirectoryID $DirectoryID
# Sending email
Send-EmailMessage -From @{ Name = 'Przemysław Kłys'; Email = '[email protected]' } -To '[email protected]' `
-Credential $Credential -HTML $Body -Subject 'This is another test email 1' -Graph -Verbose -Priority High
# sending an email with From as a string (it won't matter for Exchange )
Send-EmailMessage -From '[email protected]' -To '[email protected]' `
-Credential $Credential -HTML $Body -Subject 'This is another test email 2' -Graph -Verbose -Priority Low
The only difference between using Standard SMTP and SMTP with Basic auth is renaming Send-MailMessage to Send-EmailMessage, adding a Graph switch, and changing SMTP Server, SMTP port to Graph API application which unfortunately requires some effort. But it's no longer necessary to play with what Microsoft offers as an alternative :-)
As part of the blog post, I'm also showing how you no longer have to use HTML/CSS to build nice-looking emails, and you can skip having to learn it, so it doesn't look ugly.
Just wanted to let you all know it's now possible to send notifications to Microsoft Teams using PowerShell and mention a specific person. I've modified my PowerShell module that makes it easy to do so.
New-AdaptiveCard -Uri $Uri {
New-AdaptiveContainer {
New-AdaptiveTextBlock -Text 'Publish Adaptive Card schema' -Weight Bolder -Size Medium
New-AdaptiveColumnSet {
New-AdaptiveColumn -Width auto {
New-AdaptiveImage -Url "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg" -Size Small -Style person
}
New-AdaptiveColumn -Width stretch {
New-AdaptiveTextBlock -Text "Przemysław Kłys <at>Przemysław Kłys</at>" -Weight Bolder -Wrap
New-AdaptiveTextBlock -Text "Created {{DATE(2017-02-14T06:08:39Z, SHORT)}}" -Subtle -Spacing None -Wrap
}
}
}
New-AdaptiveContainer {
New-AdaptiveTextBlock -Text "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation." -Wrap
New-AdaptiveFactSet {
New-AdaptiveFact -Title 'Board:' -Value 'Adaptive Card'
New-AdaptiveFact -Title 'List:' -Value 'Backlog'
New-AdaptiveFact -Title 'Assigned to:' -Value 'Matt Hidinger'
New-AdaptiveFact -Title 'Due date:' -Value 'Not set'
}
}
# we need to tell PSTeams to match <at> tags to the user's profile using UPN or AAD ID
New-AdaptiveMention -Text 'Przemysław Kłys' -UserPrincipalName '[email protected]'
} -FullWidth
I wanted to introduce you today to my new PowerShell module. Actually a couple of them, and to remind you a bit about my other PowerShell modules. Hope you like this one. This PowerShell module is able to extract Active Directory data as can be seen below. If you want to find out more: https://evotec.xyz/what-do-we-say-to-writing-active-directory-documentation/
It covers usage, code explanation, examples, and a few other things. Generally all the know/how (no ads/no pay software). It's free and open source. All of it.
And just a small update on my Find-Events command... I've added one more report Organizational Unit Changes (move/add/remove). So the default list now covers:
ADComputerChangesDetailed
ADComputerCreatedChanged
ADComputerDeleted
ADGroupChanges
ADGroupChangesDetailed
ADGroupCreateDelete
ADGroupEnumeration
ADGroupMembershipChanges
ADGroupPolicyChanges
ADLogsClearedOther
ADLogsClearedSecurity
ADUserChanges
ADUserChangesDetailed
ADUserLockouts
ADUserLogon
ADUserLogonKerberos
ADUserStatus
ADUserUnlocked
ADOrganizationalUnitChangesDetailed (added in 2.0.10)
I've spent the last few days writing this. I'd very much appreciate any critiques or advice for improving it. And please let me know if it is helpful!
This script uses XAML to build a GUI to list profiles on a remote computer. You can select profiles and delete them. It uses CIM instances to get the profiles and remove them.
I got started on PowerShell GUIs by this post WPF GUIs for Beginners by /u/FarsideSC and this was my first real project with what I learned.
Last few months I've been working on 2 PowerShell modules - ADEssentials and Testimo. One provides detailed, fully automated commands to deliver different AD cmdlets. The other one uses those to deliver automated reporting.
With Get-WinADDFSHealth command you can a simple summary of your DFS Health
But also additional details you can expand on
Invoke-Testimo, on the other hand, delivers the results in form Pass/Fail making it easy to quickly asses if your DFS is working or not without spending more then 5 minutes per day on it.
And if you're really into the full report - Invoke-Testimo does that as well
But it also is able to do a lot more as you can tell it to run multiple reports at once:
It's that time of the year where this will be my last blog post and module for 2019. I had this ready for a few weeks already but wanted to fix some minor bugs that were bugging me just a bit too much.
I was thinking that it would be great to add a new PSWrite module into my portfolio so today I'm adding (officially) PSWritePDF.
Standalone functions such as Split-PDF, Merge-PDF or Convert-PDFtoText
Bundled functions working like PSWriteHTML where they are not supposed to be used separately mainly to create PDF files (for now - as I am not yet sure how to approach reading PDF
Some features:
Extract text from PDF
# Get all pages text
Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf"
# Get page 1 text only
Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -Page 1
Creating PDF - it works, but I guess it's not prime time ready. It's a bit ugly in how it looks.
New-PDF -MarginTop 200 {
New-PDFPage -PageSize A5 {
New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
New-PDFList -Indent 3 {
New-PDFListItem -Text 'Test'
New-PDFListItem -Text '2nd'
}
}
New-PDFPage -PageSize A4 -Rotate -MarginLeft 10 -MarginTop 50 {
New-PDFText -Text 'Hello 1', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
New-PDFList -Indent 3 {
New-PDFListItem -Text 'Test'
New-PDFListItem -Text '2nd'
}
}
} -FilePath "$PSScriptRoot\Example01_WithSectionsMargins.pdf" -Show
Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually on individual machines, and decided to just script the whole thing. I hope this helps other techs and admins.
De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; removes default Metro apps (Win8/8.1/2012 only)
Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates
Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD
Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)
! tron.bat:prep: Fix faulty disk health check (was exiting regardless what user chose). Thanks to/u/Tyrannosaurus_flex
! tron.bat:date and time: Reset CUR_DATE after finishing virus scans, since they take so long and we sometimes cross into a new day (therefor leaving CUR_DATE incorrect). Thanks to/u/ScubaSteve
* tron.bat:prep: Minor update to log header and trailer: Stamp what mode we're in (safe, safe with network, etc) and the location of the log file
+ tron.bat:prep: Enable "legacy" boot menu on Windows 8 and up (re-enable F8 functionality)
+ tron.bat:Feature: Add shutdown flag (-o) and corresponding DO_SHUTDOWN variable to poweroff system when Tron finishes. Overrides auto-reboot (-r) if set. Thanks to/u/Stealth5325and/u/Fogest
+ tron.bat:Feature: Add verbose flag (-v) and corresponding VERBOSE variable. Displays, when possible, verbose/debug output from each program Tron calls (Sophos, Vipre, etc). NOTE: Tron will take much longer with this option enabled
The master script (tron.bat) is available on Github here. Note: this is only the script and doesn't include the utilities Tron relies on to function. Simply downloading the script won't work - you need contents of the \resources folder and it must be organized how tron.bat expects.
Command-Line Support
Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.
Usage: tron.bat [-a -c -d -o -p -r -s -v] | [-h]
Optional flags (can be combined):
-a Automatic/silent mode (no welcome screen)
-c Config dump (display current config. Can be used with other
flags to see what WOULD happen, but script will never execute
if this flag is used)
-d Dry run (run through script but don't execute any jobs)
-o Power off after running (overrides -r if used together)
-p Preserve power settings (don't reset power settings to default)
-r Reboot automatically (auto-reboot 30 seconds after completion)
-s Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
-v Verbose. Display as much output as possible. NOTE: Significantly slower!
Misc flags (must be used alone)
-h Display this help text
Integrity
checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.
Please suggest modifications and fixes; community input is helpful and appreciated.
Last week I've released PowerShell cmdlets for Visual Nested Group Membership. This time I'm releasing two new cmdlets to deal with Active Directory Trusts.
Get-WinADTrust
Show-WinADTrust
They differ a bit from your standard ActiveDirectory cmdlets providing more information and giving some visual representation.
I've attached screenshots to show what you can expect from it. The cmdlets allow you to traverse trusts recursively if it's possible.
You would use it like:
Get-WinADTrust | ft
Get-WinADTrust -Recursive | ft
Or to show
Show-WinADTrust -Online -Verbose -Recursive
I also added one cool feature where you can control conditional formatting based on on your needs in the table. With just 2-3 more lines you can control output just like you would normally do in PSWriteHTML.
Show-WinADTrust -Online -FilePath $PSScriptRoot\Reports\TrustsWithColors.html -Verbose {
TableHeader -Names 'TrustBase', 'TrustType', 'TrustTypeAD' -Color Blue -Title 'Types'
TableCondition -Name 'TrustDirection' -BackgroundColor red -Color white -Value 'Bidirectional' -Operator eq -ComparisonType string
TableCondition -Name 'Level' -BackgroundColor blue -Color white -Value 0 -Operator eq -ComparisonType number
}
A couple people express interest in seeing a script to automate cleaning up old local profiles on computers. This is one I wrote and run monthly via task scheduler. My organization sees employees moving around a lot, so this has been really handy to keep the computers clean.
It works by getting a list of computers from a file, and it will use Runspace to open multiple threads to delete profiles older than a certain number of days. This script is set for 30 days, but you can change that. The multi-threading allows the script to clean up a lot of computers at once. I went from the script taking hours to complete to a few minutes. It usually takes 5 to 15 minutes to go through the ~400 computers at my organization.
It isn't perfect, it uses LastUseTime to determine when how long a profile hasn't been used, but sometimes a program or service will go in and update a profile even if the profile isn't being used.
Here it is. Please let me know if you have any issues with it or if you see any ways to improve it. And if it is useful, please let me know!
We found out one of our colleagues is still on 512kb/s when the rest of us are on fibre, so I wrote this powershell primarily to mock him.
The script asks you for a few input parameters and then tells you how many pigeons it will take to transport your data and how long it will take them. It then offers a comparison based on your bandwidth
The values are based on 80kmph average speed of a carrier pigeon and 3x32GB usb sticks as the max carry weight of the pigeon (75g)
###::: This script prompts for data inputs and then calculates whether sending your data via carrier pigeon would be faster than sending it via the internet
###::: ask what bandwidth you have in mbps
$bandwidth = Read-Host -Prompt 'what is your bandwidth in mbps?'
###::: ask how much data there is in GB
$dataload = Read-Host -Prompt 'How much data do you wish to transfer in GB?'
###::: how many KM the data will travel
$distance = Read-Host -Prompt 'How many KM must the data travel?'
###::: convert roughly to megabits
$dataloadmbits = ($dataload / 0.0001)
$Pigeonspeed = [math]::round($distance / 80,2)
$pigeoncount = [math]::ceiling($dataload / 96)
$datatransfer = [math]::round(($dataloadmbits / $bandwidth) / 3600,2)
echo "it will take $pigeoncount pigeons $pigeonspeed hours to carry your data"
echo "compared to $datatransfer hours on your bandwidth"
Posted this over there a few days ago. Figured I'd post it here:
So I was looking to do some testing for an AD migration, or maybe automate a few pain points I've been running into. In order to do this I needed "Real" names for my ad users. I threw together this script for the lab network.
The script has a few parts the first part are the global functions that will change per use case.
#preset variables for the script:
$date = Get-date -format M.d.yyyy
#AD specific info
$ou="OU=LANDING,DC=DEFAULTDOMAIN,DC=COM"
$principlename = "@DEFAULT.com"
$description = "Test Account Generate $date"
#Number of accounts generated:
$Number_of_users = "5000"
#Supported Nationalities: AU, BR, CA, CH, DE, DK, ES, FI, FR, GB, IE, IR, NL, NZ, TR, US
#Comma seperated values for multiple ie:
#$nationalities ="US,DK,FR"
$nationalities ="US"
The second part is 2 functions I wrote:
generate : Creates an AD password acceptable for the basic policy
find_ad_id: Confirms that the Sam account name is not already taken. This currently attempts First letter of the first name full last name, and then crawls through the first name before giving up and logging the error.
The rest is simply pulling Json data from randomuser.me.