[Download PowerGUI] [Download Notepad++]
PowerShell 3.0 Language Reference -
PowerShell_LangRef_v3.pdf
Books I recommend
(click to look inside)
![bar1](http://eddiejackson.net/web_images/lightgraybar.bmp)
To be added:
Cycling through list
Get-ExecutionPolicy Set-ExecutionPolicy RemoteSigned Get-Help About_Signing get-command get-command -Verb Get get-command -Noun Service Get-Help Get-Help
* Get-Help Get-Service get-service
∆
Copy file
Copy-Item c:\scripts\test.txt c:\test
∆
Create New Folder
New-Item c:\scripts\Windows PowerShell -type directory
∆
Create New File
New-Item c:\scripts\new_file.txt -type file
∆
Force new file
New-Item c:\scripts\new_file.txt -type file -force
∆
Move file
Move-Item c:\scripts\test.zip c:\test -force
∆
Delete File
Remove-Item c:\scripts\test.txt
∆
Rename File
Rename-Item c:\scripts\test.txt new_name.txt
∆
Message Popup
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Windows.Forms.MessageBox]::Show("Test message from eddiejackson.net!", "Popup", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
∆
If Exist
Test-Path c:\scripts\test.txt
∆
Sleep
Start-Sleep -s 10
∆
Get top 10 memory consuming programs
Get-Process | Sort-Object pm ,desc | Select-Object
,first 10
∆
Running powershell without starting powershell
powershell.exe -noexit &'c:\my scripts\test.ps1'
∆
How to get input
[string]$c = Read-Host "Enter computer name"
∆
Get Date/Time
get-Date
∆
Get Time only
Get-Date -displayhint time
∆
Running a program
Invoke-Item c:\windows\system32\calc.exe
∆
Terminate a process
Stop-Process 3512 Stop-Process -processname notepad Stop-Process -processname note*
∆
Display Date/Time in different formats
"" "Date / Format YYYYMMDD DD-MM-YYYY MM/DD/YYYY" "============================================================" "Yesterday " + (get-date (get-date).AddDays(-1) -uformat %Y%m%d) +
" " + (get-date (get-date).AddDays(-1) -uformat %d-%m-%Y) +
" " + (get-date (get-date).AddDays(-1) -uformat %m/%d/%Y) "Today " + (get-date -uformat %Y%m%d) +
" " + (get-date (get-date) -uformat %d-%m-%Y) +
" " + (get-date (get-date) -uformat %m/%d/%Y) "Tomorrow " + (get-date (get-date).AddDays(1) -uformat %Y%m%d) +
" " + (get-date (get-date).AddDays(1) -uformat %d-%m-%Y) +
" " + (get-date (get-date).AddDays(1) -uformat %m/%d/%Y)
∆
Cycling Through List
PS C:\> $names = get-content "c:\computers.txt" PS C:\> foreach ($name in $names)
{ >> $name >> gwmi Win32_OperatingSystem -prop ServicePackMajorVersion -comp $name >>
} >>
∆
Retrieve Username via Explorer.exe
param( [string]$strComputer = "." )
$colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" -computername $strComputer
foreach ($objItem in $colItems)
{ write-host "Name :" $objItem.Name write-host "Version :" $objItem.Version write-host "Manufacturer :" $objItem.Manufacturer write-host "SMBIOSBIOS Version :" $objItem.SMBIOSBIOSVersion write-host
}
∆
Eject CDROM
param( [string] $help )
if ( $help -eq "" ) { $colCDROMs = ( new-object -COM WMPlayer.OCX.7 ).cdromCollection for ( $i = 0; $i -lt $colCDROMs.count ; $i++ ) { $colCDROMs.Item( $i ).eject( )
} } else { write-host write-host "CDEject.ps1, Version 1.00" write-host "Eject all CDROMs" write-host
}
(Get-WmiObject -class win32_process | where{$_.ProcessName -eq 'explorer.exe'}).getowner() | Select -property domain, user
∆
List BIOS Info
Accessing WMI and outputting useful info - I removed many properties
param( [string]$strComputer = "." )
$colItems = get-wmiobject -class "Win32_ComputerSystem" -namespace "root\CIMV2" -computername $strComputer
foreach ($objItem in $colItems) { write-host "Admin Password Status :" $objItem.AdminPasswordStatus write-host "Automatic Reset Boot Option :" $objItem.AutomaticResetBootOption write-host "Automatic Reset Capability :" $objItem.AutomaticResetCapability write-host "Boot Option On Limit :" $objItem.BootOptionOnLimit write-host "Boot Option On Watch Dog :" $objItem.BootOptionOnWatchDog write-host "Boot ROM Supported :" $objItem.BootROMSupported write-host }
∆
Show Screen Resolution
param( [string]$strComputer = "." )
$colItems = get-wmiobject -class "Win32_DisplayConfiguration" -namespace "root\CIMV2" -computername $strComputer
foreach ($objItem in $colItems)
{ write-host "Device Name :" $objItem.DeviceName write-host "Pels Width :" $objItem.PelsWidth write-host "Pels Height :" $objItem.PelsHeight write-host "Bits Per Pel :" $objItem.BitsPerPel write-host "Display Frequency :" $objItem.DisplayFrequency write-host }
∆
retrieves a list of all available cmdlets
Get-Command
∆
displays help information about cmdlets and concepts
Get-Help
∆
retrieves management information by using WMI
Get-WMIObject
∆
retrieves Windows event logs
Get-EventLog
∆
retrieves a single or list of active processes
Get-Process
∆
retrieves a Windows service
Get-Service
∆
reads in text files, treating each line as a child object
Get-Content Get-Content c:\scripts\test.txt Get-Content c:\scripts\test.txt | Foreach-Object {Get-Wmiobject -computername $_ win32_bios}
∆
appends content to a text file
Add-Content Add-Content c:\scripts\test.txt "The End" Add-Content c:\scripts\test.txt "`nThe End"
∆
copies files, folders, and other objects
Copy-Item
∆
retrieves access control lists (ACLs)
Get-Acl
∆
Compares 2 text files, displays the diff
param( [string]$orgfile, [string]$diffile, [string]$switch
)
If ( $diffile -eq "" )
{ Write-Host Write-Host "TxtComp.ps1, Version 1.00" Write-Host "Compare 2 text files and display the differences" Write-Host Write-Host "Usage: .\TXTCOMP.PS1 file1 file2 [ /ALL ]" Write-Host Write-Host "Where: file1 and file2 are the files to be compared" Write-Host
" /ALL display all lines, not just the differences" Write-Host Write-Host } Else
{ If ( $switch -eq "/ALL" ) { Compare-Object $( Get-Content $orgfile ) $( Get-Content $diffile ) -IncludeEqual } Else
{ Compare-Object $( Get-Content $orgfile ) $( Get-Content $diffile ) }
}
.....
|
|
|
About
I'm a Computer
Systems Engineer
Living and loving life ........................................
Author ....
![](http://eddiejackson.net/web_images/icon_twitter.png)
..
|