Script library add

This commit is contained in:
silversword411 2021-05-12 11:25:22 -04:00
parent dfe97dd466
commit 3dc92763c7
No known key found for this signature in database
GPG Key ID: 6F4BD176F56B50CA
3 changed files with 51 additions and 0 deletions

View File

@ -341,6 +341,15 @@
"shell": "powershell",
"category": "TRMM (Win):Active Directory"
},
{
"guid": "3afd07c0-04fd-4b23-b5f2-88205c0744d4",
"filename": "Win_User_Admins_Local_Disable.ps1",
"submittedBy": "https://github.com/dinger1986",
"name": "Local Administrators - Disables all local admins if joined to domain or AzureAD",
"description": "Checks to see if computer is either joined to a AD domain or Azure AD. If it is, it disables all local admin accounts. If not joined to domain/AzureAD, leaves admin accounts in place",
"shell": "powershell",
"category": "TRMM (Win):User Management"
},
{
"guid": "71090fc4-faa6-460b-adb0-95d7863544e1",
"filename": "Win_Check_Events_for_Bluescreens.ps1",

View File

@ -0,0 +1,42 @@
<#
.SYNOPSIS
Disables all local admins if joined to domain or AzureAD
.DESCRIPTION
Checks to see if computer is either joined to a AD domain or Azure AD. If it is, it disables all local admin accounts. If not joined to domain/AzureAD, leaves local admin accounts in place
.OUTPUTS
Results are printed to the console.
.NOTES
Change Log
5/12/2021 V1.0 Initial release
Contributed by: https://github.com/dinger1986
#>
$ErrorActionPreference = 'silentlycontinue'
if (get-localuser | Where-Object Enabled) {
if (dsregcmd /status | Where-Object { $_ -match 'DomainJoined : YES' } | ForEach-Object { $_.Trim() }) {
Write-Output "Removing Local Admins"
get-localuser | Where-Object Enabled | Disable-LocalUser
get-localuser | Select name, Enabled
}
elseif (dsregcmd /status | Where-Object { $_ -match 'AzureAdJoined : YES' } | ForEach-Object { $_.Trim() }) {
Write-Output "Removing Local Admins"
get-localuser | Where-Object Enabled | Disable-LocalUser
get-localuser | Select name, Enabled
}
else {
Write-Output "Machine not on Domain so leaving local admins"
get-localuser | Select name, Enabled
}
}
else {
Write-Output "No local Users"
}