PowerShell Notes

Install programs through enter pssession

ISE is dope



How to tell if script exited succsfully

-last exit code

-so do an if to see if it exited with $last exit code


Java script
-taskkill.exe iexplore.exe
-taskkill.exe chrome.exe

Using regular expressions to search for critical errors through log files
Using the pipeline to ping multiple computers,
using pipeline to connect to multiple computers

-transmits data from one cmmdlet to another
-data must be passed into the pipeline to be continued
-converttocsv transmits data through the pipeline
-exporttocsv does not
-clixml has better hierarchy than a .csv file

Rejoin computer to domain
Test-computersecurechannel –repair
Objects have properties


Objects usually have methods as well, use get-member (or gm) to get details on them

PowerShell.exe -Command "Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File "F:\VMs\StartVMs.ps1"' -Verb RunAs"

Importing csvs
-first line is header, then deliminator is used as properties

There are 5 pipelines






-verbosepreference = continue

Copy the scripts to people’s computers using a login script so I can run it on their machines

For each script, have a “pre execution” and “post execution” functions with stuff like stopping windows updates, checking for hard drive space, etc. easier to run and easier to maintain.

Have event IDs be dynamic variables that are set in the parameters. Then change all the numbers to “$script normal event” or “$script error event” to allow for easier management.

Switch –wildcard ($name) “*DC*” or -regex
-“break” to exit switch command

try, catch
-use finally to eliminate redundant code

use hashtable to add properties to psobject

write output instead of return

begin, process, end blocks for functions

Looping Constructs

-similar to foreach-object

change ok button on gpresult program to grey out "ok"
show progress or powershell status in program
variables for task sequence to install certain programs: “tax”, “assurance”, “best”

Best Practices List for functions

-Use Jobs for background tasks to eliminate waiting
-scripts have help info
-scripts have parameters
-parameters have help
-parameters have properties that are defined and controlled
-scripts use error handling
-scripts have try/catch blocks with error output
-scripts use verbose logging options

For changing an OS imaging process, create a PowerShell Script that takes a need, change and tests and inserts it into an excel change management sheet

Run argument list as a string that you built before
$argList = "C: \\Computer1\ServerBackups$\$ComputerName\$JobTitle.vhd /accepteula"
Start-Process -filepath "C:\Powershell-Backup\disk2vhd.exe" -argumentlist $argList

Use {0} and then -f $Variable to build string reliably
$FilePath = ("C:\Users\{0}\Appdata") -f $Username
$FilePath = "C:\Users\$Username\Appdata"


Popular posts from this blog

Application Doesn't Install During OSD Task Sequence in SCCM


Checklist for PowerShell Commandlets/Functions