Powershell

kies u onderdeel


Paltas lessen

Problemen?







            Beveiligd signed script:
            Set-ExecutionPolicy -ExecutionPolicy Allsigned

        
..

  Code voor users in ad toevoegen:

                  
Import-Module ActiveDirectory 

$ADUsers = Import-Csv C:\Users\Administrator\Desktop\users.csv -Delimiter ";"

foreach ($User in $ADUsers) {

  
    $username = $User.firstname
    $firstname = $User.firstname
    $lastname = $User.lastname
    $string = Read-Host -AsSecureString
    $password = ConvertTo-SecureString -String $string -AsPlainText -Force
 
 
    if (Get-ADUser -F { SamAccountName -eq $username }) {

        Write-Warning "A user account with username $username already exists in Active Directory."
    }
    else {

        
        New-ADUser `
            -SamAccountName $username `
            -UserPrincipalName $username `
            -Name "$firstname $lastname" `
            -GivenName $firstname `
            -Surname $lastname `
            -Enabled $True `
            -AccountPassword $password -ChangePasswordAtLogon $True

        Write-Host "The user account $username is created." -ForegroundColor Cyan
    }
}

Read-Host -Prompt "Press Enter to exit"

                  
                






  AD met password csv

                  
$ADUsers = Import-Csv C:\Users\Administrator\Desktop\users.csv -Delimiter ";" 

 

foreach ($User in $ADUsers) { 

  $username = $User.firstname 

  $firstname = $User.firstname 

  $lastname = $User.lastname

  $list = $User.password 

  $password = ConvertTo-SecureString -String $list -AsPlainText -Force 


  if (Get-ADUser -F { SamAccountName -eq $username }) { 

 

    Write-Warning "A user account with username $username already exists in Active Directory." 

  } 

  else { 

 

     

    New-ADUser `
    -SamAccountName $username `
    -UserPrincipalName $username `
    -Name "$firstname $lastname" `
    -GivenName $firstname `
    -Surname $lastname `
    -Enabled $True `
    -AccountPassword $password -ChangePasswordAtLogon $True

 

    Write-Host "The user account $username is created." -ForegroundColor Cyan 

  } 

} 

 

Read-Host -Prompt "Press Enter to exit" 

                  
                






  Get-Process in black en whitelist

                  
Write-Host "Script started at: $(Get-Date)"
If (!(Test-Path C:\Users\rickd\Desktop\examen\Whitelist.txt)) {New-Item -ItemType File -Path C:\Users\rickd\Desktop\examen\Whitelist.txt} 

elseIf (Test-Path C:\Users\rickd\Desktop\examen\Whitelist.txt) {$Whitelist = Get-Content C:\Users\rickd\Desktop\examen\Whitelist.txt}

If (!(Test-Path C:\Users\rickd\Desktop\examen\Blacklist.txt)) {New-Item -ItemType File -Path C:\Users\rickd\Desktop\examen\Blacklist.txt} 

elseIf (Test-Path C:\Users\rickd\Desktop\examen\Blacklist.txt) {$Blacklist = Get-Content C:\Users\rickd\Desktop\examen\Blacklist.txt}

$processes = Get-Process | Where-Object {!($whitelist -contains $_.ProcessName)}
foreach ($process in $processes) {
    $toevoeging = Read-Host "The process $($process.ProcessName) is niet gevonden in de whitelist. Wil je hem toevoegen?(j, n ,annuleer, exit)"
    switch ($toevoeging) {
        "j" {
            Add-Content C:\Users\rickd\Desktop\examen\Whitelist.txt $process.ProcessName
            Write-Host "Het process $($process.ProcessName) is toegevoegd tot de  whitelist."
        }
        "n" {
            Add-Content C:\Users\rickd\Desktop\examen\Blacklist.txt $process.ProcessName
            Write-Host "Het process $($process.ProcessName) is toegevoegd tot de blacklist."
        }
        "annuleer" {
            Write-Host "Het process $($process.ProcessName) is niet toegevoegd tot de whitelist of blacklist."
        }
        "exit" {
            exit
        }
        
    }
    foreach ($process in $processes) {
        if ($blacklist -contains $process.ProcessName) {
            Write-Warning "Verdachte activiteit. het process: $($process.ProcessName) staat in de blacklist."
        }
    }
}


                    
                  
                






  SQL

                  
CREATE DATABASE test;

CREATE TABLE IF NOT EXISTS `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `voornaam` varchar(50) NOT NULL,
  `achternaam` varchar(50) NOT NULL,
  `adres` VARCHAR(50) NOT NULL,
  `huisnummer` VARCHAR(10) NOT NULL,
  `woonplaats` VARCHAR(50) NOT NULL,
  `postcode` varchar(6) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) 

INSERT INTO `student` (`id`, `voornaam`, `achternaam`, `adres`, `huisnummer`, `woonplaats`, `postcode`) VALUES
    (10, 'Rick', 'de Jong', 'Horizoncollege', '24', 'Hoorn', '1624 NP');
 
SELECT id FROM `student`;

SELECT * FROM student
WHERE voornaam='Rick';

UPDATE student
SET adres = 'zwaag'
WHERE id = 10;