PowerShell v2 Day 4


Day 4

$Voice = New-Object -ComObject SAPI.SPVoice


$voice.Rate = -10

$Voice.Speak("hello from powershell")

$voice.Rate = 10

$Voice.Speak("hello from powershell")


Get-Module -ListAvailable

import-module ActiveDirectory -verbose

cd AD:

cd DC=blah,DC=local

New-PSDrive -Name BLAH -PSProvider ActiveDirectory -Root "DC=Blah,DC=Local" -Credential (get-credential)

Get-ADUser -Filter { samaccountname -like "*admin*"}

Get-ADUser -Filter { memberof -recursiveMatch $(grp.DistinguishedName)

Get-ADObject -Filter { ServicePrincipalName -like "*"} -Properties ServicePrincipalName | select Name, ServicePrincipalName

Get-ADUser Kevin | set-ADUser -Replace @{ physicalDeliveryOfficeName = "Boise" }

$user = get-ADUser Kevin - Properties *

$user.office  = "Blah"

Set-AdUser -Instance $User


  Active Directory Explorer sysinternals



gci $HOME -Recurse | ? { ($_ | get-acl).owner -eq "$env:UserDomain\$env:Username"}

$acl = gci C:\config.sys | Get-Acl

$acl | fl *

$acl.AddAccessRule # returns an error of what you need

$ace=New-Object system.security.accesscontrol.FileSystemAccessRule "Domain\User","FullControl","Allow"


Set-Acl -Path C:\config.sys -AclObject $acl


WMI Type Accelerators page 525

[wmiclass] "Win32_Process"

([wmiclass] "Win32_Process").Create("notepad.exe")

([wmiclass] "\\server01\root\cimv2:Win32_Process").Create("notepad.exe")

.Net way of doing this




Get-Content blah.xml

$xml=[xml] (get-content blah.xml)

$xml | gm


get-command *xml* -CommandType cmdlet

select-xml -Xml $xml -XPath "//site"

select-xml -Xml $xml -XPath "//site" |% { $_.Node}

select-xml -Xml $xml -XPath "//site" | Select-Object -ExpandProperty Node

Type Adaptation 

Module 3 page 235

Get-Process explorer | Get-Member -View Extended

Get-Process explorer | Get-Member -View Base

Get-Process explorer | Get-Member -View Adapted

Get-Process explorer | Get-Member -View Adapted,Extended

get-help Get-Member -Parameter view

(Get-Process explorer).psobject

$Process = Get-Process explorer




$Process | Add-Member -MemberType ScriptProperty -Name CurrentTime -Value { Get-Date }



$Process | Add-Member -MemberType ScriptMethod -Name GetCurrentTime -Value { Get-Date }











          ## Ensure that this is a FileSystem drive

          if($this.Provider.ImplementingType -eq



             $driveRoot = ([System.IO.DirectoryInfo] $this.Root).Name.Replace('\','')

      $drive = Get-WmiObject Win32_LogicalDisk -Filter "DeviceId='$driveRoot'"

             $drive.Size - $drive.FreeSpace







          ## Ensure that this is a FileSystem drive

          if($this.Provider.ImplementingType -eq



             $driveRoot = ([System.IO.DirectoryInfo] $this.Root).Root.Name.Replace('\','')

      $drive = Get-WmiObject Win32_LogicalDisk -Filter "DeviceId='$driveRoot'"







Get-PSDrive | gm

Update-TypeData .\NewTypeDat.ps1xml

Module 3 Exercise 2




Heading foo


PS Code Here

$To = "Kevin Curran <kcurran@blah.com>"