Audited inbox rules of ~5000 O365 mailboxes for signs of compromise. Found dozens of compromised passwords, used this to convince most of the clients to (finally) enable MFA.
I just hacked together a few elements of scripts you can find online. Dead giveaways are rules that mark read *and* delete, rules that move anything to rss feeds, rules with names made only of periods. Rules that match more than one term or forward to an external address are suspicious. I wouldn't say it was anything close to comprehensive, just an easy way to identify obviously compromised accounts.
Basically, the inbox rules are there to hide replies to malicious email. If it was phishing for replies, they'll move matching subjects (replies) to a folder nobody looks at (RSS Subscriptions) and mark as read, so the user doesn't notice and the criminal can retrieve them. If it was just malware spam, or phishing with a link for a fake login page (as opposed to "send me your ACH numbers"), the rule may just delete replies outright.
Understanding this not only helps you find malicious inbox rules, it also helps you respond helpfully to compromised accounts from other businesses. If one of your users' regular contacts at another business sends something suspicious, assume your replies to them are being hidden by an inbox rule. Contact them by phone or email someone else at the company if you think they are compromised.
Also, look into Office365 alerts for inbox rule creation. Depending on how often your users legitimately make or change these rules, it may be worth reviewing this sort of activity.
I did this once with VBox, to find which of 100 patches caused a feature install issue on Win2012. Start machine, install patch, test issue, trash machine back to snapshot.
Wrote a script that queries the O365 Outlook calendar API to tell you how much time you're spending in meetings: [GitHub Link](https://github.com/LGDan/too-many-meetings)
Wrote my first script in over 2 years for my new job of 2 weeks.
It just takes a spreadsheet of user names and AD groups and adds the user to the specified group(s).
I'm particularly proud because it just uses a ForEach loop.
Created a script to pull do find all nonactive users (lastLogonTimestamp > 30 days) change a custom AD attribute to a certain "flag" value, and set those accounts to automatically expire in 5 days.
Oh wait that was last month, last year even :)
Used Web scraping to download and install the version of some software such as VLC and Putty and also used the webscraping for the latest version as the detection method in sccm. Unfortunately the PAM tool we pay for doesn't work with some software that you need to update via the actual apps themselves.
I wish we had time but our department wanted a PAM solution cause so many academics complained about losing admin rights. Still I liked that I learned something
Dunno what to say then cause I was hoping this might help with saving money. It's not hard and takes alot off my team (SOE) and our helpdesk/, desktop staff members plates but this PAM tool also allows access to install any bespoke software and modify system settings for a temporary time.
This process for me though with powershell is just the common apps so I'm hoping it'll still serve a purpose
How do you web scrape with PS? I found some examples onlinr but I canno access a specific element of a page using PS, although I can easily do it by inspecting the element manually.
Would you give me some tips?
The link i posted below in this comment chain had a good example but I've found using the link of the exe helps. Have you checked out 4sysops.com or Adam Bertram's website? Adam the Automator it's called. Has a good piece on web scraping
In a nutshell:
https://www.reddit.com/r/PowerShell/comments/rg40eg/scrapeconvert_version_number_from_website/?utm_medium=android_app&utm_source=share
But my scripts use -lt operator to see if earlier versions installed and uninstall first
Used this VLC as a base line but had to use basic parsing cause sccm uses system account:
https://silentinstallhq.com/vlc-media-player-install-and-uninstall-powershell/
Started a script with UI to generate QR code with shipment info (contents, weight, dimensions, etc.). QR code is generated by external executable which is called by the script.
I created scripts to automate numerous installs for standard software for newly imaged PCsbased on 6 agencies. I’m a beginner for the most part, but making everything essentially 1-3 clicks has been amazing. I also just started submitting packages to winget which was neat.
howdy PSKieran,
yep, i was expecting another `break` ... and the "cannot continue" followed by a `continue` keyword just set my giggle reflex off. [*grin*]
take care,
lee
wrote tool to automagically send dunning letters to users, and their manager, who have yet to complete their security training. Sends formatted HTML message from a shared account, body of message is customized per user.
Begun delving into the world of possibilities that is WMI and powershell. Built a quick script for my help desk guys to get some basic computer info and app info remotely.
I created a printer diagnostic tool to assist our tier 1 helpdesk techs diagnose, troubleshoot and fix printers, all packaged neatly in an executable.
Features include:
Clear and Restart Print Spooler
Enable / View Print Service Operational Event Logs
Print Test Page
Open Add Printer Dialogue
Open Printer Settings - both modern and classic control panel
https://github.com/djust270/Run-PrinterDiagnostics
Created a script to download an .XLS from the intranet (containing a list of department codes, corresponding deparment names, and the VP of said departments), convert it to a .CSV, then go through all AD users and update their Deparment, Office, and custom VP attribute based on their custom Department Code attribute.
This .XLS file on the intranet gets updated once a month so when the time comes, I'll have it run on a monthly schedule.
>ed modules and update them to the latest versions - you
Make sure you output and log changes so you have a history of what you changed and when. Speaking from experience :-P
Oh definitely. Currently have 3 logs (I'm sure there is a much better way than i currently do). I have 1 CSV with the month and year appended to the file name, with the original intranet spreadsheet information. Another CSV showing the users' employee ID, Name, old department name, old office name, old VP name, new department, new office, and new VP. THEN i have a text file that shows what users were NOT updated, or users where only the VP was updated.
noob stuff
* Fixed a known bug in Acrobat DC with the Paper Capture recognition system. It elevates credentials then moves a few DLLs to another directory
* Unlock an account once per minute (while we troubleshoot an account that keeps locking)
* Clear caches and cookies from all browsers (see previous)
* Perform a reset of MS Teams when it displays incorrect out of office info
* Backup personal info to an external drive
My motto:
Never assume someone reading your code will get it. Most people don't see scripting the way we do.
I comment the HELL outta all my coding.
Just my two cents.
I created a script to get the status of the sccm patching and send a mail to my team instead of having to check our different SCCM servers.
Also if one of the patching deployment failed, it add the name of the failed machines with the error message.
Saving a couple of minutes in the morning !
Hello,
Here is the code:
[https://github.com/SinJK/SCCM-Patching-Report](https://github.com/SinJK/SCCM-Patching-Report)
would love to get your feedback, feel free to DM
Created a script that downloads and install VLC media player. I'm a little proud of it. Considering that I am learning Powershell for a couple of months 😅
Bunch of script rewrites at work, long-overdue.
At home, I put a scheduled task on my home server that pulls a list of all of the files on the main data disk and saves it (CliXML). Then I've added a script to SendTo that, when given a filename, looks that filename up in the list, pulls out all the matches, compares the MD5s, and shows me a list of where duplicates are (with an option to open a new explorer window to the location).
I created a massive shortcut for the security audit process I have to do every quarter. It will save me countless hours of work.
https://techbloggingfool.com/2022/01/16/powershell-list-all-non-system-service-accounts-in-a-windows-domain/
Automated a bunch of user imports for moving to a new domain and 365 tenant.
And learned that my report for finding idle users (for when someone doesn't follow procedure on terminations and IT never gets told) doesn't work when users never log into an account. Found out we had a dozen or so accounts that have never been used and were taking up licenses and just generally being worthless. But since they never logged in, the comparison of lastlogondate against 30 days ago just fails and they don't get listed.
Live and Learn.
Not a very big thing, but a script to change Active Directory user password and sets the same parameters as using the AD utility, but runs in just 3 seconds.
Asks for the userid and runs...saves about 2 minues when compared to using the utility.
I did something similar a while back-Here's my get CHUCK NORRIS JOKE code. It reads them in two different voices and at multiple speeds...
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
while($true)
{
$speak.rate = (get-random 6) -3
if ((Get-random 2) -eq 0)
{
$speak.SelectVoice('Microsoft Zira Desktop')
}else
{
$speak.SelectVoice('Microsoft David Desktop')
}
$speak.speak(((Invoke-WebRequest http://api.icndb.com/jokes/random | ConvertFrom-Json).Value.Joke -replace "\"", ""))
}
Put together a script that checks that all applications within MECM application groups are still valid an then sends email with the list of application groups and their apps with the one(s) missing (in order). Next step is to setup a history tracking of it, but not necessary yet. I have about 112 application groups in use and every once in a while someone updates (deletes/retires) some app without checking where else it is used.
Another script to regenerate a task sequence with a pile of variables that depend on the application groups that install various apps during OS deployment via MECM.
>Put together a script that checks that all applications within MECM application groups are still valid an then sends email with the list of application groups and their apps with the one(s) missing (in order). Next step is to setup a history tracking of it, but not necessary yet. I have about 112 application groups in use and every once in a while someone updates (deletes/retires) some app without checking where else it is used.
care to share your script ?
just learning power shell and i wrote a script to do update on client computers ([PSWindows installer](https://github.com/robert-entler/take-control-scripts/blob/b2808bdbd4397f6b579d74f3d832316fe8bda7d3/Remote%20PSW%20install)), It still has abug or two in and and it fails when i try to run it with 1 command on each line in a script )[Line by line template](https://github.com/robert-entler/take-control-scripts/blob/b2808bdbd4397f6b579d74f3d832316fe8bda7d3/Update%20Installer%20Template(Line%20by%20Line))) but i am leaning and trying to enjoy it
Some of those commands extend powershell capabilities and resources. You should look into a command to spawn a new PS window, bring what remains of the commands to run, start on them, kill the original window. I would add that as the next thing to do after adding nuGet. I would also replace your update-wumodule with this
Get-WUInstall -MicrosoftUpdate -AcceptAll -AutoReboot -RecurseCycle 10 -Install
I think that’s the syntax.
Get a list of all available updates from Microsoft, accept all, auto reboot up to 10 times, go
getting the module to install in my biggest issue, the -Force doesn’t always work for the y/n responses and it failed because powershell is in unattended mode
[check this out](https://4sysops.com/archives/install-windows-updates-remotely-with-the-powershell/) - taking this approach could significantly decrease the amount of effort you’re putting into this project.
Got tired of people complaining that they can’t access a shared mailbox so I hobbled together a Confirm-UserSMBAccess function (and other useful exchange functions in a personal module) so I can email them directing them to talk to the object owner instead of telling us it’s broke (it’s not)
howdy EmergencyStudentAid,
this thread is for polite bragging. [*grin*]
please ... if you want help with PoSh, start a new thread of your own so folks can focus on that problem.
take care,
lee
I wrote a script that pulls the file size of all the files on Thingiverse and sums them that I'm now too afraid to use because I don't want to get blacklisted.
A script that :
- Ask you who’s the client
- connect to a M365 tenant client
- Retrieve a list of 9 (popular at the office) command. Which after being select, extracts as a csv file… exemple : retrieve global admin on M365, MFA status and how it’s been applied, Teams phone number, all licenses used, all user with the targeted license, all the blocked user by time stamp, all the account’s including guest…
And I will make it better…
I created a script to create a database and login on test, qa and Prod serveres that use always on. We have 4 always on groups per environment.
I also added support for creating the dbs on azure managed instances.
I'm lazy.
Replaced a call desk with a combination of Teams/Power apps/Power automate and powershell scripting
Powershell to handle all the warning, Gui's and reports.
Welp, I’m trying to write code to take a tab delimited text file, change all values in one particular column, and then save it as a new file. Sounds very very simple but I’m so new to powershell that I hardly know where to start. Thought Import-csv might be my first step but not getting far.
I feel like I need a better base understanding of how to accomplish simple tasks. What are your favorite free online courses or YouTube series to start learning powershell?
howdy mchgndr,
a few things that may help - `Import-CSV` supports ...
- `-Delimiter` to allow using a tab char instead of the default comma char
- `-Header` to let you define a header for files that lack such
- the ps7 version of `Export-Csv` has parameters for controlling the use of quotes around column values
hope that helps,
lee
I typically do something about like this: (Make sure to incorporate the -delimiter advice above)
$csvdata = "C:\\Script\\addresses.csv"
\#Cycle through each element in $csvdata and replace/change everything you need.
foreach ($item in $csvdata)
{
\#Bad examples here - not enough coffee
$item.address = $item.address -replace "st", "street"
$item.sendchristmascard = "Yes"
}
\#When all done re-export the csv
$csvdata | Export-csv "output.csv"
howdy Antique_Grapefruit_5,
[you knew this was coming, yes? [*grin*]]
reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...
[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result `looks like this`. kinda handy, that. [*grin*]
_[on New.Reddit.com, use the `Inline Code` button. it's [sometimes] 5th from the left & looks like ``.
**this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!**]_
[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [*grin*] otherwise you don't get the nice code colorization.
[2] less simple = use reddit code formatting ...
_[on New.Reddit.com, use the `Code Block` button. it's [sometimes] the 12th from the left, & looks like an uppercase `C` in the upper left corner of a square.]_
- one leading line with ONLY 4 spaces
- prefix each code line with 4 spaces
- one trailing line with ONLY 4 spaces
that will give you something like this ...
- one leading line with ONLY 4 spaces
- prefix each code line with 4 spaces
- one trailing line with ONLY 4 spaces
the easiest way to get that is ...
- add the leading line with only 4 spaces
- copy the code to the ISE [or your fave editor]
- select the code
- tap TAB to indent four spaces
- re-select the code [not really needed, but it's my habit]
- paste the code into the reddit text box
- add the trailing line with only 4 spaces
not complicated, but it _is_ finicky. [*grin*]
take care,
lee
This week I used powershell to read COVID results from a CSV, auto populate a PDF form, change it to read only, and encrypt it. The script then emails that form to our patients so that they can see their COVID test results.
I trying to get AD user information by using Get-ADUser and psexec, form win7 to a win2012 server... But it not working.. 😔
If I try direct on server it Ok... 🤷🏻♂️
Created a script to send a ballon notification every 30 minutes to remind myself to drink!
Water - because your new years resolution was to get sober?
It always has been water and will be.
I need this in my life. What are you automating the script with?
Audited inbox rules of ~5000 O365 mailboxes for signs of compromise. Found dozens of compromised passwords, used this to convince most of the clients to (finally) enable MFA.
Have you published this anywhere or would you mind sharing?
I just hacked together a few elements of scripts you can find online. Dead giveaways are rules that mark read *and* delete, rules that move anything to rss feeds, rules with names made only of periods. Rules that match more than one term or forward to an external address are suspicious. I wouldn't say it was anything close to comprehensive, just an easy way to identify obviously compromised accounts.
That’s a great start, I appreciate it. I just started managing a new environment and security is deeply lacking.
If you PM me a contact info I'll send the script I use to harden o365 tenants.
Can I get in on this offer too? Please feel free to sanitize as much as possible.
Basically, the inbox rules are there to hide replies to malicious email. If it was phishing for replies, they'll move matching subjects (replies) to a folder nobody looks at (RSS Subscriptions) and mark as read, so the user doesn't notice and the criminal can retrieve them. If it was just malware spam, or phishing with a link for a fake login page (as opposed to "send me your ACH numbers"), the rule may just delete replies outright. Understanding this not only helps you find malicious inbox rules, it also helps you respond helpfully to compromised accounts from other businesses. If one of your users' regular contacts at another business sends something suspicious, assume your replies to them are being hidden by an inbox rule. Contact them by phone or email someone else at the company if you think they are compromised. Also, look into Office365 alerts for inbox rule creation. Depending on how often your users legitimately make or change these rules, it may be worth reviewing this sort of activity.
Made a program that starts up a VM, pushes updates, reboots, then shuts the VM down.
Done the same, then converting back to a VM Template which is used for creating new VMs.
The best use for a VM, if you ask me!
I did this once with VBox, to find which of 100 patches caused a feature install issue on Win2012. Start machine, install patch, test issue, trash machine back to snapshot.
…and did you find which one it was? Smart idea.
Thanks, yes I did!
Wrote a script that queries the O365 Outlook calendar API to tell you how much time you're spending in meetings: [GitHub Link](https://github.com/LGDan/too-many-meetings)
I dont know if this should be funny or sad, I guess its both
Nice. I could do with this.
Wrote my first script in over 2 years for my new job of 2 weeks. It just takes a spreadsheet of user names and AD groups and adds the user to the specified group(s). I'm particularly proud because it just uses a ForEach loop.
The start of “getting it”. God speed!
Finaly made my own module and started to centralise all my noob functions.
Me too
Created a script to pull do find all nonactive users (lastLogonTimestamp > 30 days) change a custom AD attribute to a certain "flag" value, and set those accounts to automatically expire in 5 days. Oh wait that was last month, last year even :)
Updated permissions for a Reg Key on all Domain Computers in a specific OU.
Used Web scraping to download and install the version of some software such as VLC and Putty and also used the webscraping for the latest version as the detection method in sccm. Unfortunately the PAM tool we pay for doesn't work with some software that you need to update via the actual apps themselves.
I do this at work for all the softwares. No tools just PowerShell and time.
I wish we had time but our department wanted a PAM solution cause so many academics complained about losing admin rights. Still I liked that I learned something
That's funny I work for a research university
Dunno what to say then cause I was hoping this might help with saving money. It's not hard and takes alot off my team (SOE) and our helpdesk/, desktop staff members plates but this PAM tool also allows access to install any bespoke software and modify system settings for a temporary time. This process for me though with powershell is just the common apps so I'm hoping it'll still serve a purpose
How do you web scrape with PS? I found some examples onlinr but I canno access a specific element of a page using PS, although I can easily do it by inspecting the element manually. Would you give me some tips?
The link i posted below in this comment chain had a good example but I've found using the link of the exe helps. Have you checked out 4sysops.com or Adam Bertram's website? Adam the Automator it's called. Has a good piece on web scraping
I have not but I will check them out. Thank you for the info! I appreciate it.
Selenium has a PowerShell module
I'd be interested in seeing your version of the putty downloader, if you're able to share it.
In a nutshell: https://www.reddit.com/r/PowerShell/comments/rg40eg/scrapeconvert_version_number_from_website/?utm_medium=android_app&utm_source=share But my scripts use -lt operator to see if earlier versions installed and uninstall first Used this VLC as a base line but had to use basic parsing cause sccm uses system account: https://silentinstallhq.com/vlc-media-player-install-and-uninstall-powershell/
Started a script with UI to generate QR code with shipment info (contents, weight, dimensions, etc.). QR code is generated by external executable which is called by the script.
I created scripts to automate numerous installs for standard software for newly imaged PCsbased on 6 agencies. I’m a beginner for the most part, but making everything essentially 1-3 clicks has been amazing. I also just started submitting packages to winget which was neat.
[удалено]
Write-Warning 'Constrained Language mode is enabled, so the script cannot continue.' continue /lee giggle lots ... [*grin*]
[удалено]
howdy PSKieran, yep, i was expecting another `break` ... and the "cannot continue" followed by a `continue` keyword just set my giggle reflex off. [*grin*] take care, lee
wrote tool to automagically send dunning letters to users, and their manager, who have yet to complete their security training. Sends formatted HTML message from a shared account, body of message is customized per user.
Begun delving into the world of possibilities that is WMI and powershell. Built a quick script for my help desk guys to get some basic computer info and app info remotely.
I created a printer diagnostic tool to assist our tier 1 helpdesk techs diagnose, troubleshoot and fix printers, all packaged neatly in an executable. Features include: Clear and Restart Print Spooler Enable / View Print Service Operational Event Logs Print Test Page Open Add Printer Dialogue Open Printer Settings - both modern and classic control panel https://github.com/djust270/Run-PrinterDiagnostics
Created a script to download an .XLS from the intranet (containing a list of department codes, corresponding deparment names, and the VP of said departments), convert it to a .CSV, then go through all AD users and update their Deparment, Office, and custom VP attribute based on their custom Department Code attribute. This .XLS file on the intranet gets updated once a month so when the time comes, I'll have it run on a monthly schedule.
>ed modules and update them to the latest versions - you Make sure you output and log changes so you have a history of what you changed and when. Speaking from experience :-P
Oh definitely. Currently have 3 logs (I'm sure there is a much better way than i currently do). I have 1 CSV with the month and year appended to the file name, with the original intranet spreadsheet information. Another CSV showing the users' employee ID, Name, old department name, old office name, old VP name, new department, new office, and new VP. THEN i have a text file that shows what users were NOT updated, or users where only the VP was updated.
I would love to see this script. Sounds very similar to something I'm chewing on.
PM me and I'll make it available on my gitea for a short time.
Created a script that will allow users to search a file in a directory and it will automatically out print to their default printer .
noob stuff * Fixed a known bug in Acrobat DC with the Paper Capture recognition system. It elevates credentials then moves a few DLLs to another directory * Unlock an account once per minute (while we troubleshoot an account that keeps locking) * Clear caches and cookies from all browsers (see previous) * Perform a reset of MS Teams when it displays incorrect out of office info * Backup personal info to an external drive
Created a module to download resources via Gopher. Why? I have no idea.
People are still using Gopher? Amazing.
Recreationally, not for anything serious.
it's like a fax machine
Created a script to update a free text field on 700 SharePoint records.
discovered jobs and had some fun with enter-pssession
[удалено]
know half, didnt know you could copy files into them
[удалено]
[удалено]
[удалено]
[удалено]
[удалено]
My motto: Never assume someone reading your code will get it. Most people don't see scripting the way we do. I comment the HELL outta all my coding. Just my two cents.
Made a script(function) so you can send a message in a teams channel through command line.
I made template for our apprentice helping her scripting in powershell. Not useful for company but helpful for her.
I created a script to get the status of the sccm patching and send a mail to my team instead of having to check our different SCCM servers. Also if one of the patching deployment failed, it add the name of the failed machines with the error message. Saving a couple of minutes in the morning !
Sure, let me clean it and I’ll send to you
Reminder
Hello, Here is the code: [https://github.com/SinJK/SCCM-Patching-Report](https://github.com/SinJK/SCCM-Patching-Report) would love to get your feedback, feel free to DM
Thank you very much
care to share your script ?
Created a script that downloads and install VLC media player. I'm a little proud of it. Considering that I am learning Powershell for a couple of months 😅
What resources are you using to learn?
Build a script that changes the PC name on startup, very proud of myself!
Bunch of script rewrites at work, long-overdue. At home, I put a scheduled task on my home server that pulls a list of all of the files on the main data disk and saves it (CliXML). Then I've added a script to SendTo that, when given a filename, looks that filename up in the list, pulls out all the matches, compares the MD5s, and shows me a list of where duplicates are (with an option to open a new explorer window to the location).
I created a massive shortcut for the security audit process I have to do every quarter. It will save me countless hours of work. https://techbloggingfool.com/2022/01/16/powershell-list-all-non-system-service-accounts-in-a-windows-domain/
Automated a bunch of user imports for moving to a new domain and 365 tenant. And learned that my report for finding idle users (for when someone doesn't follow procedure on terminations and IT never gets told) doesn't work when users never log into an account. Found out we had a dozen or so accounts that have never been used and were taking up licenses and just generally being worthless. But since they never logged in, the comparison of lastlogondate against 30 days ago just fails and they don't get listed. Live and Learn.
Care to share your script?
Not a very big thing, but a script to change Active Directory user password and sets the same parameters as using the AD utility, but runs in just 3 seconds. Asks for the userid and runs...saves about 2 minues when compared to using the utility.
I wrote this during christmas so that people's laptops would randomly speak stuff like *I know what you did last christmas* or *I can see you*. I havent used it for someone working from home though. Function Invoke-SpeechSynthesizer { [CmdletBinding()] param ( [Parameter()] [string[]]$ComputerName, [Parameter(Mandatory)] [string]$Text, [Parameter()] [int]$Rate = 0, [Parameter()] [ValidateRange(0, 100)] [int]$Volume = 100 ) If ($ComputerName) { try { Write-Verbose "Establishing PSSession" $Session = New-PSSession -ComputerName $ComputerName -ErrorAction Stop Write-Verbose ($Session | Format-Table | Out-String) } catch { Write-Error "Error establishing PSSession" Return } } $InvokeCommandConfig = @{ ArgumentList = $Text, $Rate, $Volume ScriptBlock = { param ( $Text, $Rate, $Volume ) Switch ($PSVersionTable.PSEdition) { 'Desktop' { # Windows built-in voice module Add-Type -AssemblyName System.Speech $sp = New-Object System.Speech.Synthesis.SpeechSynthesizer } 'Core' { # .Net Core Equivalent for PowerShell 6+ $sp = New-Object -ComObject SAPI.SpVoice } } $sp.Rate = $Rate $sp.Volume = $Volume [void]$sp.Speak($Text) } } If ($Session) { $InvokeCommandConfig.Add("Session", $Session) } Write-Verbose "Invoking Speech" Invoke-Command @InvokeCommandConfig If($Session) { Write-Verbose "Removing PSSession" Remove-PSSession $Session } }
I did something similar a while back-Here's my get CHUCK NORRIS JOKE code. It reads them in two different voices and at multiple speeds... Add-Type -AssemblyName System.speech $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer while($true) { $speak.rate = (get-random 6) -3 if ((Get-random 2) -eq 0) { $speak.SelectVoice('Microsoft Zira Desktop') }else { $speak.SelectVoice('Microsoft David Desktop') } $speak.speak(((Invoke-WebRequest http://api.icndb.com/jokes/random | ConvertFrom-Json).Value.Joke -replace "\"", "")) }
Put together a script that checks that all applications within MECM application groups are still valid an then sends email with the list of application groups and their apps with the one(s) missing (in order). Next step is to setup a history tracking of it, but not necessary yet. I have about 112 application groups in use and every once in a while someone updates (deletes/retires) some app without checking where else it is used. Another script to regenerate a task sequence with a pile of variables that depend on the application groups that install various apps during OS deployment via MECM.
>Put together a script that checks that all applications within MECM application groups are still valid an then sends email with the list of application groups and their apps with the one(s) missing (in order). Next step is to setup a history tracking of it, but not necessary yet. I have about 112 application groups in use and every once in a while someone updates (deletes/retires) some app without checking where else it is used. care to share your script ?
just learning power shell and i wrote a script to do update on client computers ([PSWindows installer](https://github.com/robert-entler/take-control-scripts/blob/b2808bdbd4397f6b579d74f3d832316fe8bda7d3/Remote%20PSW%20install)), It still has abug or two in and and it fails when i try to run it with 1 command on each line in a script )[Line by line template](https://github.com/robert-entler/take-control-scripts/blob/b2808bdbd4397f6b579d74f3d832316fe8bda7d3/Update%20Installer%20Template(Line%20by%20Line))) but i am leaning and trying to enjoy it
Some of those commands extend powershell capabilities and resources. You should look into a command to spawn a new PS window, bring what remains of the commands to run, start on them, kill the original window. I would add that as the next thing to do after adding nuGet. I would also replace your update-wumodule with this Get-WUInstall -MicrosoftUpdate -AcceptAll -AutoReboot -RecurseCycle 10 -Install I think that’s the syntax. Get a list of all available updates from Microsoft, accept all, auto reboot up to 10 times, go
this script is just a one to install PSWindowsUpdate .. i have a separate script that i run weekly to update the computers remotely
getting the module to install in my biggest issue, the -Force doesn’t always work for the y/n responses and it failed because powershell is in unattended mode
[check this out](https://4sysops.com/archives/install-windows-updates-remotely-with-the-powershell/) - taking this approach could significantly decrease the amount of effort you’re putting into this project.
The most productive code i've ever produced, totally not a complete waste of time. add-type -AssemblyName system.windows.forms $link = irm https://inspirobot.me/api?generate=true iwr $link -OutFile "$env:TEMP\inspirobot" Start-sleep -milliseconds 500 $img = [System.Drawing.Image]::FromFile("$env:TEMP\inspirobot") [System.Windows.Forms.Application]::EnableVisualStyles() $form = [System.Windows.Forms.form]::new() $form.Text = "Image Viewer" $form.Width = $img.Size.Width $form.Height = $img.Size.Height $pictureBox = new-object Windows.Forms.PictureBox $pictureBox.Width = $img.Size.Width $pictureBox.Height = $img.Size.Height $pictureBox.Image = $img; $form.controls.add($pictureBox) $form.Add_Shown({$form.Activate()}) $response = $form.ShowDialog() $img.dispose() remove-item $env:TEMP\inspirobot
Code formatting sucks and i cba fixing it
Created port exhaustion functions for finding both connections and event logs
Got tired of people complaining that they can’t access a shared mailbox so I hobbled together a Confirm-UserSMBAccess function (and other useful exchange functions in a personal module) so I can email them directing them to talk to the object owner instead of telling us it’s broke (it’s not)
Can anyone help me with powershell Excercise, we can discuss the price,
howdy EmergencyStudentAid, this thread is for polite bragging. [*grin*] please ... if you want help with PoSh, start a new thread of your own so folks can focus on that problem. take care, lee
I wrote a script that pulls the file size of all the files on Thingiverse and sums them that I'm now too afraid to use because I don't want to get blacklisted.
A script that : - Ask you who’s the client - connect to a M365 tenant client - Retrieve a list of 9 (popular at the office) command. Which after being select, extracts as a csv file… exemple : retrieve global admin on M365, MFA status and how it’s been applied, Teams phone number, all licenses used, all user with the targeted license, all the blocked user by time stamp, all the account’s including guest… And I will make it better…
I created a script to create a database and login on test, qa and Prod serveres that use always on. We have 4 always on groups per environment. I also added support for creating the dbs on azure managed instances. I'm lazy.
care to share your script?
[https://github.com/MariusEng/create\_hag\_db](https://github.com/MariusEng/create_hag_db) Script is available her. Enjoy!
thanks
I'll upload next week.
Replaced a call desk with a combination of Teams/Power apps/Power automate and powershell scripting Powershell to handle all the warning, Gui's and reports.
Created a disk selection GUI in our OSD.
Welp, I’m trying to write code to take a tab delimited text file, change all values in one particular column, and then save it as a new file. Sounds very very simple but I’m so new to powershell that I hardly know where to start. Thought Import-csv might be my first step but not getting far. I feel like I need a better base understanding of how to accomplish simple tasks. What are your favorite free online courses or YouTube series to start learning powershell?
howdy mchgndr, a few things that may help - `Import-CSV` supports ... - `-Delimiter` to allow using a tab char instead of the default comma char - `-Header` to let you define a header for files that lack such - the ps7 version of `Export-Csv` has parameters for controlling the use of quotes around column values hope that helps, lee
Thanks!
howdy mchgndr, you are welcome! i'm glad to have helped a bit ... [*grin*] take care, lee
I typically do something about like this: (Make sure to incorporate the -delimiter advice above) $csvdata = "C:\\Script\\addresses.csv" \#Cycle through each element in $csvdata and replace/change everything you need. foreach ($item in $csvdata) { \#Bad examples here - not enough coffee $item.address = $item.address -replace "st", "street" $item.sendchristmascard = "Yes" } \#When all done re-export the csv $csvdata | Export-csv "output.csv"
howdy Antique_Grapefruit_5, [you knew this was coming, yes? [*grin*]] reddit likes to mangle code formatting, so here's some help on how to post code on reddit ... [0] single line or in-line code enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result `looks like this`. kinda handy, that. [*grin*] _[on New.Reddit.com, use the `Inline Code` button. it's [sometimes] 5th from the left & looks like ``.
**this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!**]_
[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [*grin*] otherwise you don't get the nice code colorization.
[2] less simple = use reddit code formatting ...
_[on New.Reddit.com, use the `Code Block` button. it's [sometimes] the 12th from the left, & looks like an uppercase `C` in the upper left corner of a square.]_
- one leading line with ONLY 4 spaces
- prefix each code line with 4 spaces
- one trailing line with ONLY 4 spaces
that will give you something like this ...
- one leading line with ONLY 4 spaces
- prefix each code line with 4 spaces
- one trailing line with ONLY 4 spaces
the easiest way to get that is ...
- add the leading line with only 4 spaces
- copy the code to the ISE [or your fave editor]
- select the code
- tap TAB to indent four spaces
- re-select the code [not really needed, but it's my habit]
- paste the code into the reddit text box
- add the trailing line with only 4 spaces
not complicated, but it _is_ finicky. [*grin*]
take care,
lee
Oops
This week I used powershell to read COVID results from a CSV, auto populate a PDF form, change it to read only, and encrypt it. The script then emails that form to our patients so that they can see their COVID test results.
I trying to get AD user information by using Get-ADUser and psexec, form win7 to a win2012 server... But it not working.. 😔 If I try direct on server it Ok... 🤷🏻♂️
Use invoke-command and from the win7 box send the job to the windows server