Powershell v2 Day 2

Blah

Class Day 2

Events

$process = Start-Process notepad.exe -PassThru

Register-ObjectEvent -InputObject $process -EventName Exited -Action {Write-warning "Somebody Closed Notepad"}

 

$process = Start-Process notepad.exe -PassThru

Register-ObjectEvent -InputObject $process -EventName Exited -Action { Write-Warning ($event.Sender.Name) + " Has exited"}

 

 


Get-WmiObject -Namespace root\cimv2 -List | Where-Object {$_.__Derivation -contains "__Event"}

 

$global:myvar=11

$local:MyVar2=33

$script:MyScriptVar=2

$private:MyPrivateVar=11

$myprivatevar

& { $myprivatevar }

$ { $myvar2 }

 

 

 

Heading foo

ddd

$Network = Import-Csv c:\LabFiles\Lab1\Network_Details.csv

$Database = Import-Csv c:\LabFiles\Lab1\Database_Details.csv

$computers=foreach ($db in $Database) {

 #$user returns an array only selecting first match

 #$user =$Network -match $db.DisplayName | select -First 1

 #Different way to do same thing

 $user = $Network | where {$_.DisplayName -eq $($db.DisplayName)}

 Write-Host "DB info: $db"

 Write-Host "Network info: $user" -ForegroundColor Green

 $db | Add-Member -MemberType NoteProperty -Name PrimarySMTPAddress -Value $($user.PrimarySMTPAddress) -PassThru

}

$computers | Export-Csv -NoTypeInformation c:\LabFiles\Lab1\Computer_Details.csv

$db = $Database[0]

$user =$Network -match $($db.DisplayName) | gm