PowerShell - Anton-L-GitHub/Learning GitHub Wiki

Windows server kursen

TOM

 

Generellt

  • Finns stöd att köra PowerShell mot linux/unix-miljöer

SYNTAX

Verb-Substantiv -attribut | Verb-Substantiv -växel 

Variabler

$min_variabel = 5;

Loops

$total = 5;

for ($diskIndex=0; $diskIndex -lt $total; $diskIndex++) {
$diskId = "{0:00}" -f ($diskIndex + 1)
$diskNamn = "Extradisk$diskID"
Write-Host "Skapar disk" ($diskIndex + 1) "av" $total ":" $diskNamn
NEW-VHD -Dynamic C:\VM\DC\$diskNamn.vhdx -SizeBytes 60GB
Add-VMHardDiskDrive -VMName DC -ControllerType SCSI -Path C:\vm\DC\$diskNamn.vhdx
}

Pipeing

  • | = Nästa del i pipen
  • > = Ger outputen till ...

Active Directory

Manage userw

Cmdlet Description
New-ADUser Creates user accounts
Set-ADUser Modifies properties of user accounts
Remove-ADUser Deletes user accounts
Set-ADAccountPassword Resets the password of a user account
Set-ADAccountExpiration Modifies the expiration date of a user account
Unlock-ADAccount Unlocks a user account after it hasbecome locked after too many incorrect login attempts
Enable-ADAccount Enables a user account
Disable-ADAccount Disables a user account

Add new user:

New-ADUser "Sten Faerch" –AccountPassword (Read-Host–AsSecureString "Enter password") -Department IT

or a better one

New-ADUser 
-Name "Staffan Stalledräng"
-GivenName "Staffan"
-Surname "Stalledräng"
-SamAccountName = "staffan"
-UserPrincipalName "[email protected]"
-Description "Kung"
-Path "OU=Användare,OU=Stockholm,DC=jultomten,DC"
-AccountPassword (ConvertTo-SecureString -AsPlainText "Linux4Ever" -Force) -passThru | Enable-ADAccount

Manage groups

cmdlet Description
New-ADGroup Creates new groups
Set-ADGroup Modifies properties of groups
Get-ADGroup Displays properties of groups
Remove-ADGroup Deletes groups
Add-ADGroupMember Adds members to groups
Get-ADGroupMember Displays membership of groups
Remove-ADGroupMember Removes members from groups
Add-ADPrincipalGroupMembership Adds group membership to objects
Get-ADPrincipalGroupMembership Displays group membership of objects
Remove-ADPrincipalGroupMembership Removes group membership from an object

Create new group:

New-ADGroup –Name "CustomerManagement" –Path "ou=managers,dc=adatum,dc=com" –GroupScope Global –GroupCategory Security

Lägg till member:

Add-ADGroupMember –Name CustomerManagement –Members "Joe" 

Manage computer accounts

cmdlet Description
New-ADComputer Creates new computer accounts
Set-ADComputer Modifies properties of computer accounts
Get-ADComputer Displays properties of computer accounts
Remove-ADComputer Deletes computer accounts
Test-ComputerSecureChannel Verifies or repairs the trust relationship between a computer and the domain
Reset-ComputerMachinePassword Resets the password for the computer account

New computer account

New-ADComputer –Name LON-SVR8 -Path "ou=marketing,dc=adatum,dc=com" -Enabled $true

Repair trust relationship to domain

Test-ComputerSecureChannel -Repair

Manage OUs

cmdlet Description
New -ADOrganizationalUnit Creates OUs
Set-ADOrganizationalUnit Modifies properties of OUs
Get-ADOrganizationalUnit Views properties of OUs
Remove-ADOrganizationalUnit Delete OUs

Create new OU

New-ADOrganizationalUnit –Name Sales –Path "ou=marketing,dc=adatum,dc=com" –ProtectedFromAccidentalDeletion $true

Installera DC

 Install-ADDSDomainController

Remote installera winfeature

Install-WindowsFeature <Feature> -ComputerName <Computername>

Ändra ett attribut för alla användare:

Get-ADUser -Filter * SearchBase "OU=Test,DC=domaincontroller,DC=local" | Set-ADuser -Department "Hej"

Make new virtual harddrive

New-VHD -Dynamic "C:\VM\lab\Extradisk.vhdx" -SizeBytes 60GB

Inspect VM

Import-Module Hyper-V

Enable-VMResourceMetering Surfdator1
Measure-VM Surfdator1

TOM

 Get-ChildItem

Powershell Kurs

CD / LS

 Get-ChildItem

Visa objektets Metoder, Properties, aliases, osv.

 Get-Member
⚠️ **GitHub.com Fallback** ⚠️