PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o...
-
Upload
gordon-flynn -
Category
Documents
-
view
227 -
download
1
Transcript of PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o...
![Page 1: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/1.jpg)
PowerShell Basics
![Page 2: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/2.jpg)
o PowerShell is a great way to manipulate server and/or workstation components
o It’s geared toward system administrators by creating a more simplified syntax base
o PowerShell is more secure than running vbscripts
o Quick analysis of various computer specs
![Page 3: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/3.jpg)
o Microsoft .NET Framework v2.0 or latero Windows XP/Server 2003 or latero The PowerShell install file (Download)o Windows Management Framework
(Includes)o Windows Remote Managemento Windows PowerShell 2.0o Background Intelligent Transfer Service
(BITS) 4.0
![Page 4: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/4.jpg)
o You can use commands that you are familiar with such as CD, PING, IPCONFIG or DIR
o There are also some Unix commands that can be used such as LS or MAN (these commands are aliases to the actual PowerShell commands)
o Get-Alias will list the preloaded Alias’s and will show you what Cmdlet they are mapped to
![Page 5: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/5.jpg)
o The majority of the PowerShell functionality comes from Cmdlet’s
o Always in Verb-Noun format and never plural (Get-WmiObject or Get-Process)
o Cmdlet’s return objects not texto Retrieve list of Cmdlet’s (Get-
Command)o Can tab complete
![Page 6: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/6.jpg)
o One of the time savers in PowerShell is giving the user the ability to pipe commands together
o Ex. Get-process | select ProcessName, ID | Sort ProcessName | FL
![Page 7: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/7.jpg)
o PowerShell scripts differ from most scripts
o PowerShell scripts end in .ps1 and have to be run inside a PowerShell window
o Double clicking a PowerShell script will open the script in notepad
o Scripts must also be run in this format
![Page 8: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/8.jpg)
o Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
o AllSigned – Only scripts signed by a trusted publisher can be run.
o RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
o Unrestricted – No restrictions; all Windows PowerShell scripts can be run.
![Page 9: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/9.jpg)
o PowerShell can tap in to the WMI classes of another computer as well your own, given you are using administrative credentials
o Ex. Get-WmiObject Win32_Product will list all of the Microsoft installed products on your machine (products installed by Windows Installer)
![Page 10: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/10.jpg)
o You can use the runas command in the ‘start’ menu to run the PowerShell console as administrator
o There is a Cmdlet called Get-Credential which can store administrative credentials in a variable
o Can’t be used to authenticate to local machine
![Page 11: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/11.jpg)
o Because WMI calls utilize the RPC protocol, the Windows Firewall must be turned off or Remote Administration must be enabled
o The RPC protocol uses random ports
![Page 12: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/12.jpg)
o Pull computer serial numbero Gwmi Win32_Bios | select SerialNumber
o Reboot a machineo (Gwmi win32_OperatingSystem –comp |
server).reboot()o Gather Logical Disk Space information
o Gwmi Win32_LogicalDisko Show running processes
o Gwmi Win32_Process
![Page 13: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/13.jpg)
o Variables are defined by the two following ways [type] $variable = x or just $variable = x
o To display a variable you would just type $variable
o Ex. To store the installed products on your machineo $Product = gwmi Win32_Product
![Page 14: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/14.jpg)
o If you displayed the contents of $Product, it would display the entire list of products that it pulled
o To individually go through each installed product you would need to use a ForEach statement
![Page 15: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/15.jpg)
o Server 2008 R2o Window 7o Exchange 2007/2010o System Center 2008 Suiteo SQL 2008/2008 R2o SharePoint 2010
![Page 16: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/16.jpg)
o www.scriptinganswers.como www.primalscript.como www.scriptingoutpost.como http://www.microsoft.com/technet/
scriptcenter/topics/winpsh/convert/default.mspxo Site Converts VB code to PowerShell Code
![Page 17: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/17.jpg)
o $NIC = Get-WMIObject Win32_NetworkAdapterConfiguration | where{$_.IPEnabled -eq "TRUE“}o $NIC.EnableStatic("192.168.100.66", "255.255.255.0")o $NIC.SetGateways("192.168.100.1")o $NIC.SetDNSServerSearchOrder(“8.8.8.8”, “8.8.4.4”)o $NIC.SetDynamicDNSRegistration("FALSE")
![Page 18: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/18.jpg)
o Gwmi win32_process | select name | sort name
o (Gwmi win32_process | where {$_.name –(match “processname.exe”}).terminate(1)
![Page 19: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/19.jpg)
o gwmi win32_terminalservicesetting -comp computername).setallowtsconnections(1)
![Page 20: PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649e715503460f94b6ff50/html5/thumbnails/20.jpg)