סקריפטים:
נתחיל מ -SCRIPT שנותן ל-POWERSHELL אופציה לעשות פעולות מתמטיות כמו חיבור, חיסור, חילוק וכפל. :
function Perform-ArithmeticOperation {
param (
[int] $a,
[int] $b,
[string] $operation
)
try {
switch ($operation) {
"+" {
$result = $a + $b
}
"-" {
$result = $a - $b
}
"*" {
$result = $a * $b
}
"/" {
if ($b -eq 0) {
throw "Cannot divide by zero"
}
$result = $a / $b
}
default {
throw "Invalid operation"
}
}
Write-Host -ForegroundColor Green "$a $operation $b = $result"
}
catch {
Write-Host -ForegroundColor DarkGray "Error: $_"
}
}
Perform calculations
Perform-ArithmeticOperation 10 5 "+"
Perform-ArithmeticOperation 10 5 "-"
Perform-ArithmeticOperation 10 5 "*"
Perform-ArithmeticOperation 10 5 "/"
Perform-ArithmeticOperation 10 0 "/"
——————————————————————————————————————–
SCRIPT TO ADD USERS TO DOMAIN:
תחילה נצטרך להתקין MOUDLE ACTIVE DIRECTORY :
Install-WindowsFeature RSAT-AD-PowerShell
——————————————————————–
Import the Active Directory module
Import-Module ActiveDirectory
Define user details
$userDetails = @(
@{
FirstName = "Avi"
LastName = "Dahan"
UserName = "ADahan"
Password = "Passw0.rd"
OU = "OU=Users,DC=domain,DC=com" # Adjust this to your specific OU
},
@{
FirstName = "Jane"
LastName = "Bordo"
UserName = "jBordo"
Password = "Passw0.rd!"
OU = "OU=Users,DC=domain,DC=com" # Adjust this to your specific OU
}
)
foreach ($user in $userDetails) {
$fullName = "$($user.FirstName) $($user.LastName)"
$userPrincipalName = "$($user.UserName)@domain.com" # Adjust domain as needed
# Create the user
New-ADUser -Name $fullName `
-GivenName $user.FirstName `
-Surname $user.LastName `
-SamAccountName $user.UserName `
-UserPrincipalName $userPrincipalName `
-Path $user.OU `
-AccountPassword (ConvertTo-SecureString $user.Password -AsPlainText -Force) `
-PasswordNeverExpires $true `
-Enabled $true
Write-Host "User $($user.UserName) created successfully."
}
——————————————————————————————————————–עכשיו נעבור לסקריפט ליצירת מייל ליוזר חדש בארגון..:
#Install the Exchange Online module if you haven't already
Install-Module -Name ExchangeOnlineManagement
#Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName youradmin@yourdomain.com
#Replace the following with the new user's details
$userPrincipalName = " thenewuser@yourdomain.com"
$displayName = "New User"
#Create a new mailbox for the user
Enable-Mailbox -Identity $userPrincipalName -Alias newuser -Database "Mailbox Database 1"
Disconnect-ExchangeOnline -Confirm:$false
#Replace the following with the new user's details
$userPrincipalName = "thenewuser@yourdomain.com"
$displayName = "New User"
#Create a new mailbox
Enable-Mailbox -Identity $userPrincipalName -Alias newuser -Database "Mailbox Database 1"
Get-Mailbox -Identity $userPrincipalName
#Install and import the necessary modules
Install-Module -Name ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
#Connect to Exchange Online
$adminUser = "youradmin@yourdomain.com"
Connect-ExchangeOnline -UserPrincipalName $adminUser
#Create a new user
$newUserPrincipalName = "newuser@yourdomain.com"
New-MailUser -Name "New User" -UserPrincipalName $newUserPrincipalName -Alias newuser -ExternalEmailAddress $newUserPrincipalName
#Enable mailbox for the new user
Enable-Mailbox -Identity $newUserPrincipalName
#Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false
——————————————————————————————————————–