1 / 7

Scripts

Scripts. Coding and Logic. What are scripts?. A script or scripting language is a computer language with a series of  commands within a file that is capable of being executed without being compiled Example script languages are: Perl PHP Python JavaScript

carolej
Télécharger la présentation

Scripts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scripts Coding and Logic

  2. What are scripts? • A script or scripting language is a computer language with a series of commandswithin a file that is capable of being executed without being compiled • Example script languages are: • Perl • PHP • Python • JavaScript • For system administration then the scripts are written for: • Linux Bash (covered in the Linux slides) • Windows Batch (covered in the Windows slides) • Windows VBScript • Windows PowerShell

  3. VBScript • Developed by Microsoft • Modeledon Visual Basic. • Used for managing computers with error handling, subroutines, and other advanced programming constructs • File extensions are: • .vbs • .vbe • Not been updated for some time • PowerShell is the current recommendation

  4. What is PowerShell? • A user interface for task automation and configuration management • It includes a command-line shell and a scripting language. • Intended to replace the command prompt • Allows you to simplify and automate tedious and repetitive tasks by creating scripts and combining multiple commands together • Contains hundreds of customizable commands, which are called cmdlets • Works with objects • Get-WmiObject -Class "win32_PhysicalMemory“ will provide the amount of installed RAM

  5. Two shells • Windows PowerShell • Command line console • Windows PowerShell ISE • ISE Integrated Scripting Environment • Graphical user interface • Allows you to easily create scripts of multiple commands • Scripts saved as .PS1 files for later execution

  6. PowerShell script to make in Notepad – save as slot.ps1 $strComputer = Read-Host "Enter Computer Name to list memory slot information" $colSlots = Get-WmiObject -Class "win32_PhysicalMemoryArray" -namespace "root\CIMV2" -computerName $strComputer $colRAM = Get-WmiObject -Class "win32_PhysicalMemory" -namespace "root\CIMV2" -computerName $strComputer $NumSlots = 0 write-host "" $colSlots | ForEach { “Memory Slots in computer: $strComputer” $NumSlots = $_.MemoryDevices } $SlotsFilled = 0 $TotMemPopulated = 0 $colRAM | ForEach { $SlotsFilled = $SlotsFilled + 1 $TotMemPopulated = $TotMemPopulated + ($_.Capacity / 1GB) } write-host "" If (($NumSlots - $SlotsFilled) -eq 0) { write-host "ALL Slots Filled, NO EMPTY SLOTS AVAILABLE!" } write-host ($NumSlots - $SlotsFilled) " of " $NumSlots " slots empty" write-host ($SlotsFilled) " of " $NumSlots " slots full" write-host "" write-host "Total Memory = " $TotMemPopulated "GB" write-host "" pause

  7. Run a PowerShell script • Right click the slot.ps1 file in file explorer • Select Run in PowerShell

More Related