Snippets Collections
$role = "DHCP"
$feature = "RSAT-DHCP"
$computers = "Server1", "Server2", "Server3"
$action = Read-Host "Enter 'install', 'uninstall', or 'check' for the role/feature"

foreach ($computer in $computers) {
    Invoke-Command -ComputerName $computer -ScriptBlock {
        if ($action -eq "install") {
            Install-WindowsFeature -Name $role, $feature -IncludeAllSubFeature -IncludeManagementTools
        } elseif ($action -eq "uninstall") {
            Uninstall-WindowsFeature -Name $role, $feature -Remove
        } elseif ($action -eq "check") {
            Get-WindowsFeature -Name $role, $feature | Format-Table -Property Name, DisplayName, Installed
        } else {
            Write-Host "Invalid action specified"
        }
    }
}
$eventlogs = "Application", "Security", "System"
$lognames = $eventlogs | ForEach-Object {$_ + ".evtx"}
$path = "C:\EventLogs\"
$date = (Get-Date).AddDays(-30)

foreach ($logname in $lognames) {
    $log = Get-WinEvent -LogName $logname -FilterXPath "*[System[TimeCreated[@SystemTime>='$date']]]"
    $log | Export-EventLog -Path "$path$logname"
}
Import-Module ActiveDirectory

$username = Read-Host "Enter the username"
$password = Read-Host "Enter the password" -AsSecureString
$firstname = Read-Host "Enter the first name"
$lastname = Read-Host "Enter the last name"
$groupname = Read-Host "Enter the group name"

New-ADUser -Name "$firstname $lastname" -SamAccountName $username -UserPrincipalName "$username@domain.com" -GivenName $firstname -Surname $lastname -Enabled $true -AccountPassword $password -ChangePasswordAtLogon $true
Add-ADGroupMember -Identity $groupname -Members $username
star

Fri Jan 27 2023 06:37:08 GMT+0000 (Coordinated Universal Time) https://www.thefunkytechguy.co.za

#powershell #activedirectory
star

Fri Jan 27 2023 04:46:32 GMT+0000 (Coordinated Universal Time)

#powershell #activedirectory

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension