bar1
    
Computers          Music & Technology          Brain/Mind & Technology         Education & Technology         My University Studies         My Toolbox       
Restricted Access 
     
 

bar1
[Shell]    [VBScript]     [PowerShell]     [HTA]     [JavaScript]     [AutoIT]     [Video Demos]     [Desktop Engineering]     [Library]     [Links]     [Misc]










Archive - PowerShell

"It's not that I am so smart, it's just that I stay with problems longer."  - Albert Einstein 
 



.Contents.

bar1
Copy
Move
Delete
Rename
Cycle through list
For loop
environmental variables
If condition
logging
registry
create popups
xxxxxx
xxxxxx
bar1
  


10% done







bar1
    

To be added:

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


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)


 


Read from a computer 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

    ....





    ..