This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Function to zip the archived log, requires .NET 4.5 | |
| function zipFiles($sourceDir, $zipFileName) | |
| { | |
| Add-Type -Assembly System.IO.Compression.FileSystem | |
| $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal | |
| [System.IO.Compression.ZipFile]::CreateFromDirectory($sourceDir, $zipFileName, $compressionLevel, $false) | |
| } | |
| # Function to zip the archived log, requires 7zip (has command line version) | |
| function create-7zip([String] $sourceDir, [String] $zipFileName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## list of users, I wanted to control exactly what got modified. | |
| ## this command will get all the users we want to work with: | |
| ### Get-ADUser -Filter * -Properties nTSecurityDescriptor | ` | |
| ### where { $_.nTSecurityDescriptor.AreAccessRulesProtected -eq $true } | ` | |
| ### select Name,SamAccountName,DistinguishedName,nTSecurityDescriptor | |
| $users = Import-Csv C:\scripts\users.csv | |
| ## allows inheritance | |
| [bool]$isProtected = $false | |
| ## preserves inherited rules | |
| [bool]$PreserveInheritance = $true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Function to zip the archived log, requires 7zip (has command line version) | |
| function Create-7zip([String] $sourceDir, [String] $zipFileName) | |
| { | |
| [string]$pathToZipExe = "C:\scripts\7zip\7za.exe"; | |
| [Array]$arguments = "a", "-tzip", "$zipFileName", "$sourceDir", "-r"; | |
| & $pathToZipExe $arguments; | |
| } | |
| # get the event that containts the filename for the archived security log | |
| # for v3.0+ Get-WinEvent -LogName Security -MaxEvents 1 -Oldest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| For use in a scheduled task on an Active Directory Domain Controller | |
| Name: Lockout Email | |
| Trigger: On event - Log: Security, Source: Microsoft-Windows-Security-Auditing, Event ID: 4740 | |
| #> | |
| $AccountLockOutEvent = Get-EventLog -LogName "Security" -InstanceID 4740 -Newest 1 | |
| $LockedAccount = $($AccountLockOutEvent.ReplacementStrings[0]) | |
| $AccountLockedAt = $($AccountLockOutEvent.ReplacementStrings[1]) | |
| $AccountLockOutEventTime = $AccountLockOutEvent.TimeGenerated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Shamelessly liberated from http://foxdeploy.com/2015/02/11/automatically-delete-old-iis-logs-w-powershell/ | |
| Because it was better than my own. | |
| #> | |
| $LogPath = "C:\inetpub\logs" | |
| $maxDaystoKeep = -30 | |
| $outputPath = "c:\CleanupTask\Cleanup_Old_logs.log" | |
| $itemsToDelete = dir $LogPath -Recurse -File *.log | Where LastWriteTime -lt ((get-date).AddDays($maxDaystoKeep)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ($host.UI.RawUI.WindowTitle -like "Administrator:*") | |
| { | |
| Write-Host -ForegroundColor Green "PowerShell is running as 'Administrator'..." | |
| } else { | |
| Write-Host -ForegroundColor Magenta "PowerShell is not running as 'Administrator'..." | |
| } | |
| # check if current user is in BUILTIN\Administrators (from https://github.com/tomasr/dotfiles/blob/master/.profile.ps1) | |
| function Get-IsAdministrator | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| This is an attempt at a script to provision a DC VM in a disposable testlab | |
| This will also set the DC as authoritative time source, DHCP, and DNS server | |
| Windows Server® 2012 and 2012 R2 Core Network Guide | |
| https://gallery.technet.microsoft.com/Windows-Server-2012-and-7c5fe8ea | |
| #> | |
| # rename the computer and reboot, this isn't needed if using Vagrant | |
| #Rename-Computer -NewName newhost -Restart -Force |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #The Third section will query each computer in the ListOfComputers.txt to get the members of the local group Administrators | |
| #$Servers = (Get-ADComputer -Filter *).name | |
| $output = 'c:\psresults\ListOfLocalAdministratorsGroup.txt' | |
| $results = New-Object System.Collections.ArrayList | |
| $objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | |
| $objgroup = $objSID.Translate([System.Security.Principal.NTAccount]) | |
| $objgroupname = ($objgroup.Value).Split("\")[1] | |
| foreach($server in (Get-ADComputer -Filter *).name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $tSize = 0 | |
| Get-ChildItem -Path \\personal\users\ -Directory -Filter "of*arc" -Exclude '* *' -Recurse | % { | |
| $pSize = 0 | |
| Get-ChildItem $_.FullName -File -Recurse | % { | |
| $pSize += $_.Length | |
| $tSize += $_.Length | |
| } | |
| $pProps = New-Object psobject -Property @{ | |
| 'user'=$(($_.FullName -split '\\')[4]); | |
| 'size'=$($pSize) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .Synopsis | |
| This Function will add "NT Authority\SYSTEM" to a folder ACL. | |
| .DESCRIPTION | |
| This Function will add "NT Authority\SYSTEM" to a folder ACL, specifically to \\folder\path\. | |
| .EXAMPLE | |
| Add-SystemToFolderACL \\folder\path\user1 | |
| .EXAMPLE | |
| Add-SystemToFolderACL user1,user2 | |
| #> |