[email protected]
Számítógépes alapismeretek 11. Előadás
I l l é s
Z o l t á n
E L T E
I K
Ami eddig volt… Számítógépek architektúrája Alapvető alkotóelemek Hardver elemek Szoftver
[email protected]
• • • •
– Gépi kódtól az operációs rendszerig – Unix alapok,Shell script I., II, awk – Windows környezet, PowerShell I.,II.
I l l é s
Z o l t á n
E L T E
I K
• Mit tudunk scriptelni? Active Directory Backup and System Restore Databases Desktop Settings Email and Messaging Files, Folders, and File Systems Group Policy Hardware
[email protected]
• • • • • • • •
… I l l é s
Z o l t á n
E L T E
I K
Univerzális! • start-sleep (60*9); write-host ("`a"*4)
[email protected]
• Tényleg bármire használhatjuk… • Pl teafőzést időzíteni
I l l é s
Z o l t á n
E L T E
I K
Hasznos egysorosok-One liners Get-Content C:\users\manson\valami.txt calc Stop-Process –name calc -confirm Get-PsDrive
[email protected]
• • • • •
"Hello there world".Split().length • select-string -pattern „vizipók" -path "C:\...\csodapok.txt" I l l é s
Z o l t á n
E L T E
I K
• set-location C:\...\manson\ps • push-location System32
[email protected]
• push-location asd -stack Stack2 • get-location -stack • get-location -stackname Stack2 I l l é s
Z o l t á n
E L T E
I K
• Listázzuk ki az összes logot ! • Get-ChildItem c:\ -Recurse -Include *.log | Format-Table
[email protected]
• Get-EventLog application > c:\fso\applog.txt
I l l é s
Z o l t á n
E L T E
I K
• (get-itemproperty HKLM:\software\microsoft\.netframework).InstallRoot • (Get-WmiObject -class "Win32_ComputerSystem").Domain • C:\PS>$p = get-process
[email protected]
• c:\PS> write-output $p
• c:\PS> $p • Rendszermanagementnél is jól használható !
I l l é s
Z o l t á n
E L T E
I K
Pl:töredezettség mentesítés
C:\
I l l é s
Z o l t á n
E L T E
I K
[email protected]
# get C: volume $Cvolume = gwmi Win32_Volume | where { $_.name –eq "C:\" } # Check if C: needs a defrag $df = $Cvolume.DefragAnalysis() # Defrag if needed if ( $df.DefragRecommended ) { $Cvolume.defrag($true) }
Mount/Unmount # mount D:\ $d = gwmi win32_volume | where {
Child Volume
$_.name -eq “D:\”} $d.mount()
# dismount D:\ $d = gwmi win32_volume | where {
$_.name -eq “D:\”}
Child Volume I l l é s
$d.dismount($true, $true)
Z o l t á n
E L T E
I K
[email protected]
Parent Volume
Shadow Copies beállítása PS C:\> $s = [WMICLASS] “ROOT\CIMv2:Win32_ShadowCopy” PS C:\> $s.Create(“C:\”, “ClientAccessible”)
[email protected]
C:\
Shadow Copies Copies + New Shadow Copy Shadow I l l é s
Z o l t á n
E L T E
I K
Shadow copy Local Disk (C:) Volume
[email protected]
Win32_ShadowCopy
I l l é s
Z o l t á n
E12L T E
I K
Megosztott könyvtárak listázása (WMI) PS C:\> $s = gwmi win32_share –co DC1; $s Path ---C:\Windows C:\
Description -----------
C:\Windows\system32\sppol\drivers c:\inetpub\wwwroot
[email protected]
Name ---ADMIN$ C$ IPC$ print$ wwwroot$
PS C:\> $s.count 5 PS C:\> $s[1] | Format-Table * -auto PS C:\> $s[1] | Get-Member
I l l é s
Z o l t á n
E L T E
I K
Megosztott könyvtárak létrehozása WMI
[WMICLASS]
PS C:\> $sc = [WMICLASS] “Win32_Share”
PS C:\> $sc.Create( “C:\Users\Public”, “Pub”, 0 ) ... ReturnValue : 0 PS C:\> gwmi Win32_Share ... Pub C:\Users\Public
I l l é s
Z o l t á n
E L T E
I K
[email protected]
PS C:\> $sc | Get-Member Create Method System.Management.Management...
PowerShell üzemmódok • 1.Parancs üzemmód – Végrehajtja a parancsot (ha tudja)
• 1mb ( informatikus barát ) írjuk csak be…
I l l é s
Z o l t á n
E L T E
I K
[email protected]
• 2.Kiértékelő üzemmód • - kiértékel… pl ( 1,2,4 )
Számolás ( Measure-object) get-childItem | measure-object –property length sum
[email protected]
-line: a sorokat számolja meg -word: a szavakat számolja meg -character: a karaktereket számolja meg
I l l é s
Z o l t á n
E L T E
I K
• E-mail küldés
$server = new-object System.Net.Mail.SmtpClient(192.168.2.1); $server.send($mail); …
I l l é s
Z o l t á n
E L T E
I K
[email protected]
$mail = new–object System.net.mail.mailmessage(„kitol@server. hu”,”
[email protected]”,”Tárgy”,”Üzenetem” )
Get-Alias Dir
I l l é s
Z o l t á n
E L T E
I K
[email protected]
PS C:\> Get-WmiObject Win32_LogicalDisk | Format-List * | Format-List Name, FileSystem, FreeSpace | Format-List f* | Format-List [nf]*
[email protected]
I l l é s
Z o l t á n
E L T E
I K
$x = @{}
[email protected]
$x += @{elso=„alma”;masodik=„beka”}
$x += @{gamma=„harmadik”}
$a = @{abc = @{x=1; y=2}; list = 1,2,@{red=1; blue = 2}} I l l é s
Z o l t á n
E L T E
I K
Reguláris kifejezések használata - match - cmatch
[email protected]
- select-string –pattern "asd" -path "
• DEMO
I l l é s
Z o l t á n
E L T E
I K
Karakter osztályok • \w • \s • \d
karakterek tabok,spacek,white spacek számok
[email protected]
• DEMO
I l l é s
Z o l t á n
E L T E
I K
• "Jeff" -match "J[aeiou]ff" (True) • "Jeeeeeeeeeeff" -match "J[aeiou]ff" (False)
I l l é s
Z o l t á n
E L T E
I K
[email protected]
• "192.168.15.20" -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" (True)
world -replace ” world” ,” planet”
[email protected]
I l l é s
Z o l t á n
E L T E
I K
Logok managelése
Get-EventLog –List Get-EventLog application
[email protected]
Get-EventLog application > c:\...\applog.txt
Get-EventLog application | Export-Clixml -Path c:\...\applog.xml Depth 2 I l l é s
Z o l t á n
E L T E
I K
Szolgáltatások managelése
I l l é s
Z o l t á n
E L T E
I K
[email protected]
Szolgáltatások lekérése: • Get-Services Szolgáltatások számolása: • (Get-Service).length Futó szolgáltatások: • (Get-Service | where-object { $_.status -eq "running" }).length
• Get-WmiObject -Class win32_service
Get-Service -Name $strService | Format-list *
I l l é s
Z o l t á n
E L T E
I K
[email protected]
| Where-Object { $_.acceptpause -eq "true" } | Select-Object name
Active Directory
Directory
PS C:\> $dom = ` [System.DirectoryServices.ActiveDirectory.Domain]::` GetCurrentDomain()
I l l é s
Z o l t á n
E L T E
I K
[email protected]
Active Directory Domain
Directory
PS C:\> $for = ` [System.DirectoryServices.ActiveDirectory.Forest]::` GetCurrentForest() PS C:\> $gc = $for.FindGlobalCatalog()
I l l é s
Z o l t á n
E L T E
I K
[email protected]
Active Directory Forest
Szerepkörök átvitele RID Role Owner
PDC Role Owner
Domain
[email protected]
Infrastructure Role Owner
PS C:\> $dc = $dom.FindDomainController() PS C:\> $dc.TransferRoleOwnership(„PdcRole‟)
I l l é s
Z o l t á n
E L T E
I K
Global Catalog Server Not a Global Catalog Server
[email protected]
Global Catalog Server
Forest
PS C:\> $gc = $for.FindGlobalCatalog() PS C:\> $gc.DisableGlobalCatalog()
I l l é s
Z o l t á n
E L T E
I K
Forest
PS C:\> $dom.RaiseDomainFunctionality(„Windows2003Domain‟)
PS C:\> $for.RaiseForestFunctionality(„Windows2008Forest‟)
I l l é s
Z o l t á n
E L T E
I K
[email protected]
Domain
$dom=[ADSI]“LDAP://dc=woodgrovebank,dc=com”
Domain
$dom=[ADSI]“LDAP://dc=cookham,dc=net”
OU $user=[ADSI]“LDAP://cn=Administrator,cn=Users, dc=woodgrovebank,dc=com” User Accounts
$user=[ADSI]“LDAP://cn=Benno Kurmann,ou=Marketing, ou=Miami,dc=woodgrovebank,dc=com”
I l l é s
Z o l t á n
E L T E
I K
[email protected]
$ou=[ADSI]“LDAP://OU=NYC,dc=woodgrovebank,dc=com”
Új user hozzáadása
Domain
PS C:\> $ou=[ADSI]“LDAP://OU=NYC,DC=woodgrovebank,DC=com”
PS C:\> $u = $ou.Create(“user”, “cn=Adina Hagege”) PS C:\> $u.Put(“sAMAccountName”, “Adina”) PS C:\> $u.SetInfo()
I l l é s
Z o l t á n
E L T E
I K
[email protected]
Users
Csoportok létrehozása PS C:\> $ou=[ADSI]“LDAP://OU=HR,DC=woodgrovebank,DC=com” PS C:\> $g = $ou.Create(“group”, “cn=Cool People”) PS C:\> $g.Put(“SAMAccountName”, “coolpeople”) PS C:\> $g.SetInfo()
[email protected]
I l l é s
Z o l t á n
E35L T E
I K
User azonosító módosítása
I l l é s
Z o l t á n
E L T E
I K
[email protected]
PS C:\> $user = [ADSI]“LDAP://cn=Benno Kurmann,` ou=Marketing,ou=Miami,DC=woodgrovebank,DC=com”
Csoport hierarchia
Global Group
Local Group
User Accounts
Global Group
Universal Group
I l l é s
Z o l t á n
E L T E
I K
[email protected]
User Accounts
I l l é s
Z o l t á n
E38L T E
I K
[email protected]
Köszönöm a figyelmet!