to see the paths in the Path environment variable
PS> $env:path
C:\LINDOWS\system32;C:\LINDOWS;C:\LINDOWS\System32\Wbem;"C:\LINDOWS\Microsoft.NET\Framew...
Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts
Saturday, January 17, 2009
create & use Function
to create a function
PS> function bootini {notepad c:\boot.ini}
to run existing function
PS> bootini <---- if above is done
PS> function bootini {notepad c:\boot.ini}
to run existing function
PS> bootini <---- if above is done
alias for Notepad
to create the alias "np" for Notepad
PS> set-alias np c:\lindows\notepad.exe
to remove the "np" alias
PS> remove-item alias:np
PS> set-alias np c:\lindows\notepad.exe
to remove the "np" alias
PS> remove-item alias:np
get-wmiObject
to get info about the BIOS on the local computer
PS> get-wmiobject win32_bios -computername nparks
SMBIOSBIOSVersion : V3.50
Manufacturer : Acer
Name : Ver 1.00PARTTBLP
SerialNumber : LXAU60J0077020D4581601
Version : ACRSYS - 6040000
PS> get-wmiobject win32_bios -computername nparks
SMBIOSBIOSVersion : V3.50
Manufacturer : Acer
Name : Ver 1.00PARTTBLP
SerialNumber : LXAU60J0077020D4581601
Version : ACRSYS - 6040000
$ variable operator
to perform an addition of two values
PS> $str1 = 4 + 5
PS> write-host "the result is" $str1
PS> $str1 = 4 + 5
PS> write-host "the result is" $str1
get-service
[] to identify the status of NT service, e.g. xmlprov
PS> get-service xmlprov | fl
Name : xmlprov
DisplayName : Network Provisioning Service
Status : Stopped
DependentServices : {}
ServicesDependedOn : {RpcSs}
CanPauseAndContinue : False
CanShutdown : False
CanStop : False
ServiceType : Win32ShareProcess
PS> get-service xmlprov | fl
Name : xmlprov
DisplayName : Network Provisioning Service
Status : Stopped
DependentServices : {}
ServicesDependedOn : {RpcSs}
CanPauseAndContinue : False
CanShutdown : False
CanStop : False
ServiceType : Win32ShareProcess
get-item
to find out the Mode, LastWriteTime, Length of current prompt
PS> get-item .
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Lindows\co
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2008-Dec-04 6:51 PM Administrator
PS> get-item .
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Lindows\co
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2008-Dec-04 6:51 PM Administrator
stuff about PowerShell
Here is my research states:
- Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
- Microsoft Windows® PowerShell is a new command-line shell and scripting language designed for system administration and automation. Built on the .NET Framework, Windows PowerShell enables IT professionals and developers control and automate the administration of Windows and applications.
- needs CLR 2.0
- processes objects (not text) based on the .NET platform.
- perform object-based (command-line) functions.
- relies heavily on the .NET framework
- all the built-in types are really .NET types
- works on xpsp2, svr2003sp1, vista sp1
- looks similar to that of MS-DOS command-line shell
- some knowledge of C# FCL, vbscript, sql, automation, DS, AD, batch
- a background in scripting and WMI are helpful
- is a Microsoft .NET-connected environment designed for administrative automation.
- provides a new approach to building commands, composing solutions, and creating management GUI tools.
- enables a system administrator to automate the administration of system resources by the execution of commands either directly or through scripts.
- run a command name can refer to
-- a Cmdlet (aka. Command-let)
-- single-function commands
-- have a verb-noun naming convention, such as Get-Help or Set-MachineName
-- an .ps1 script file
-- an executable file with the extension .bat, .cmd, .com, or .exe
-- WSH files with a .vbs, .js, .wsh, or .wsf extension rely on the WSH engine
-- UNIX Bash Shell internal command, e.g. man, clear, cat, mount, popd, sleep, h, ps, history, pushd, tee, kill, pwd, lp, r, write, diff, ls
- properties ( bits of data )
- methods ( actions )
- Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
- Microsoft Windows® PowerShell is a new command-line shell and scripting language designed for system administration and automation. Built on the .NET Framework, Windows PowerShell enables IT professionals and developers control and automate the administration of Windows and applications.
- needs CLR 2.0
- processes objects (not text) based on the .NET platform.
- perform object-based (command-line) functions.
- relies heavily on the .NET framework
- all the built-in types are really .NET types
- works on xpsp2, svr2003sp1, vista sp1
- looks similar to that of MS-DOS command-line shell
- some knowledge of C# FCL, vbscript, sql, automation, DS, AD, batch
- a background in scripting and WMI are helpful
- is a Microsoft .NET-connected environment designed for administrative automation.
- provides a new approach to building commands, composing solutions, and creating management GUI tools.
- enables a system administrator to automate the administration of system resources by the execution of commands either directly or through scripts.
- run a command name can refer to
-- a Cmdlet (aka. Command-let)
-- single-function commands
-- have a verb-noun naming convention, such as Get-Help or Set-MachineName
-- an .ps1 script file
-- an executable file with the extension .bat, .cmd, .com, or .exe
-- WSH files with a .vbs, .js, .wsh, or .wsf extension rely on the WSH engine
-- UNIX Bash Shell internal command, e.g. man, clear, cat, mount, popd, sleep, h, ps, history, pushd, tee, kill, pwd, lp, r, write, diff, ls
- properties ( bits of data )
- methods ( actions )
automates the Upgrade to Win95
This script automates the upgrade to Windows 95, using settings from the existing Windows installation except for User Information. Setup will prompt for a User Name and Organization. You can modify this script to predefine the user name. This script also automatically installs the Accessibility features, and contains entries that can be modified to create a hands-free installation using predefined settings.
[SETUP]
; 0 = stop for user input, 1 = do not stop for user input
Express=1
; 0 = do not create startup disk, 1 = create startup disk
EBD=0
; 0 = do not allow user to choose Uninstall and do not back up existing Windows
; 1 = show Uninstall options for user to choose
; 5 = automatically create backup files for uninstalling Windows 95
uninstall=0
; 0 = prompt for confirmation before overwriting more recent files
; 1 = overwrite without confirmation
vrc=1
; Remove ";" and set this value to your 10-digit Windows 95 product ID,
; which is printed on the Windows 95 CD or your Certification of Authenticity.
ProductID=26099-oem-0070957-53008
; 0 = compact, 1 = typical, 2 = portable, 3 = custom setup type
InstallType=1
; Remove ";" from the value for your timezone
;TimeZone="Afghanistan"
;TimeZone="Alaskan"
;TimeZone="Arabian"
;TimeZone="Atlantic"
;TimeZone="AUS Central"
;TimeZone="Azores"
;TimeZone="Bangkok"
;TimeZone="Canada Central"
;TimeZone="Cen. Australia"
;TimeZone="Central"
;TimeZone="Central Asia"
;TimeZone="Central Pacific"
;TimeZone="China"
;TimeZone="Czech"
;TimeZone="Dateline"
;TimeZone="E. Europe"
;TimeZone="E. South America"
;TimeZone="Eastern"
;TimeZone="Egypt"
;TimeZone="Fiji"
;TimeZone="GFT"
;TimeZone="GMT"
;TimeZone="Greenwich"
;TimeZone="Hawaiian"
;TimeZone="India"
;TimeZone="Iran"
;TimeZone="Israel"
;TimeZone="Lisbon Warsaw"
;TimeZone="Mexico"
;TimeZone="Mid-Atlantic"
;TimeZone="Mountain"
;TimeZone="New Zealand"
;TimeZone="Newfoundland"
;TimeZone="Pacific"
;TimeZone="Romance"
;TimeZone="Russian"
;TimeZone="SA Eastern"
;TimeZone="SA Pacific"
;TimeZone="SA Western"
;TimeZone="Samoa"
;TimeZone="Saudi Arabia"
;TimeZone="South Africa"
;TimeZone="Sydney"
TimeZone="Taipei"
;TimeZone="Tasmania"
;TimeZone="Tokyo"
;TimeZone="US Eastern"
;TimeZone="US Mountain"
;TimeZone="W. Europe"
;TimeZone="West Asia"
;TimeZone="West Pacific"
; If you modify this script to define the user information,
; set Display=0 in the following section to skip the prompt.
; Type correct values for Name= and Org=, or accept defaults.
[NAMEANDORG]
; 0 = do not prompt for user name information (use defaults)
; 1 = prompt for user and company identification
Display=0
; Set a blank default user name.
; to avoid using the user name from previous Windows installation.
; Or type a name between the quotes to predefine this information.
Name="Kent Clark"
; Set a blank default company.
; Or type text between the quotes to predefine the company name.
Org="Fishery Inc."
[NETWORK]
; 0 = do not prompt for network components during Custom setup type,
; so Setup will only use detection to install networking.
; 1 = prompt for network components
Display=0
; The following section defines which components to install.
; 0 = do not install component, 1 = install component
; This script installs Accessibility features automatically.
; The other options specified here are the defaults for Custom setup type.
[OptionalComponents]
"Accessibility Options"=0
"Accessories"=1
"Communications"=1
"Disk Tools"=1
"Multimedia"=1
"Screen Savers"=0
"Disk compression tools"=0
"Paint"=1
"HyperTerminal"=0
"Defrag"=1
"Calculator"=1
"Backup"=0
"Phone Dialer"=0
"Flying Windows"=0
"Microsoft Fax"=0
"Microsoft Fax Services"=0
"Microsoft Fax Viewer"=0
"The Microsoft Network"=0
"Audio Compression"=1
"Video Compression"=1
"Sound Recorder"=0
"Volume Control"=1
"Media Player"=1
"Microsoft Exchange"=0
"Microsoft Mail Services"=0
"Briefcase"=0
"Document Templates"=1
"WordPad"=1
"Dial-Up Networking"=0
"Direct Cable Connection"=0
"Mouse Pointers"=0
"Windows 95 Tour"=0
"Online User's Guide"=0
"Desktop Wallpaper"=0
"System Monitor"=0
"Net Watcher"=0
"Character Map"=0
"Additional Screen Savers"=0
"Games"=0
"Quick View"=1
"System Resource Meter"=0
"CompuServe Mail Services"=0
"Sample Sounds"=1
"Musica Sound Scheme"=0
"Jungle Sound Scheme"=0
"Robotz Sound Scheme"=0
"Utopia Sound Scheme"=0
"CD Player"=1
I write an unattended script called msbatch.inf and place it together with the Win95 cabinet files onto a CD.
[SETUP]
; 0 = stop for user input, 1 = do not stop for user input
Express=1
; 0 = do not create startup disk, 1 = create startup disk
EBD=0
; 0 = do not allow user to choose Uninstall and do not back up existing Windows
; 1 = show Uninstall options for user to choose
; 5 = automatically create backup files for uninstalling Windows 95
uninstall=0
; 0 = prompt for confirmation before overwriting more recent files
; 1 = overwrite without confirmation
vrc=1
; Remove ";" and set this value to your 10-digit Windows 95 product ID,
; which is printed on the Windows 95 CD or your Certification of Authenticity.
ProductID=26099-oem-0070957-53008
; 0 = compact, 1 = typical, 2 = portable, 3 = custom setup type
InstallType=1
; Remove ";" from the value for your timezone
;TimeZone="Afghanistan"
;TimeZone="Alaskan"
;TimeZone="Arabian"
;TimeZone="Atlantic"
;TimeZone="AUS Central"
;TimeZone="Azores"
;TimeZone="Bangkok"
;TimeZone="Canada Central"
;TimeZone="Cen. Australia"
;TimeZone="Central"
;TimeZone="Central Asia"
;TimeZone="Central Pacific"
;TimeZone="China"
;TimeZone="Czech"
;TimeZone="Dateline"
;TimeZone="E. Europe"
;TimeZone="E. South America"
;TimeZone="Eastern"
;TimeZone="Egypt"
;TimeZone="Fiji"
;TimeZone="GFT"
;TimeZone="GMT"
;TimeZone="Greenwich"
;TimeZone="Hawaiian"
;TimeZone="India"
;TimeZone="Iran"
;TimeZone="Israel"
;TimeZone="Lisbon Warsaw"
;TimeZone="Mexico"
;TimeZone="Mid-Atlantic"
;TimeZone="Mountain"
;TimeZone="New Zealand"
;TimeZone="Newfoundland"
;TimeZone="Pacific"
;TimeZone="Romance"
;TimeZone="Russian"
;TimeZone="SA Eastern"
;TimeZone="SA Pacific"
;TimeZone="SA Western"
;TimeZone="Samoa"
;TimeZone="Saudi Arabia"
;TimeZone="South Africa"
;TimeZone="Sydney"
TimeZone="Taipei"
;TimeZone="Tasmania"
;TimeZone="Tokyo"
;TimeZone="US Eastern"
;TimeZone="US Mountain"
;TimeZone="W. Europe"
;TimeZone="West Asia"
;TimeZone="West Pacific"
; If you modify this script to define the user information,
; set Display=0 in the following section to skip the prompt.
; Type correct values for Name= and Org=, or accept defaults.
[NAMEANDORG]
; 0 = do not prompt for user name information (use defaults)
; 1 = prompt for user and company identification
Display=0
; Set a blank default user name.
; to avoid using the user name from previous Windows installation.
; Or type a name between the quotes to predefine this information.
Name="Kent Clark"
; Set a blank default company.
; Or type text between the quotes to predefine the company name.
Org="Fishery Inc."
[NETWORK]
; 0 = do not prompt for network components during Custom setup type,
; so Setup will only use detection to install networking.
; 1 = prompt for network components
Display=0
; The following section defines which components to install.
; 0 = do not install component, 1 = install component
; This script installs Accessibility features automatically.
; The other options specified here are the defaults for Custom setup type.
[OptionalComponents]
"Accessibility Options"=0
"Accessories"=1
"Communications"=1
"Disk Tools"=1
"Multimedia"=1
"Screen Savers"=0
"Disk compression tools"=0
"Paint"=1
"HyperTerminal"=0
"Defrag"=1
"Calculator"=1
"Backup"=0
"Phone Dialer"=0
"Flying Windows"=0
"Microsoft Fax"=0
"Microsoft Fax Services"=0
"Microsoft Fax Viewer"=0
"The Microsoft Network"=0
"Audio Compression"=1
"Video Compression"=1
"Sound Recorder"=0
"Volume Control"=1
"Media Player"=1
"Microsoft Exchange"=0
"Microsoft Mail Services"=0
"Briefcase"=0
"Document Templates"=1
"WordPad"=1
"Dial-Up Networking"=0
"Direct Cable Connection"=0
"Mouse Pointers"=0
"Windows 95 Tour"=0
"Online User's Guide"=0
"Desktop Wallpaper"=0
"System Monitor"=0
"Net Watcher"=0
"Character Map"=0
"Additional Screen Savers"=0
"Games"=0
"Quick View"=1
"System Resource Meter"=0
"CompuServe Mail Services"=0
"Sample Sounds"=1
"Musica Sound Scheme"=0
"Jungle Sound Scheme"=0
"Robotz Sound Scheme"=0
"Utopia Sound Scheme"=0
"CD Player"=1
I write an unattended script called msbatch.inf and place it together with the Win95 cabinet files onto a CD.
install Device drivers automatically
Managing those device drivers can be collected into a CD, however, administering them tends to harder to handle. So, I write a DOS batch file called autoinst.bat:
echo off
echo chipset driver...
start "installing..." /wait "E:\_apbk\Drivers-xp\chipset\setup.exe" -s
echo graphics driver..
start "installing..." /wait "E:\_apbk\Drivers-xp\video\setup.exe" -s
echo audio driver...will reboot pc
start "installing..." /wait "E:\_apbk\Drivers-xp\Audio\setup.exe" -b -s
that install motherboard chipset driver, followed by video and then audio. Lastly, it will restart Windows.
echo off
echo chipset driver...
start "installing..." /wait "E:\_apbk\Drivers-xp\chipset\setup.exe" -s
echo graphics driver..
start "installing..." /wait "E:\_apbk\Drivers-xp\video\setup.exe" -s
echo audio driver...will reboot pc
start "installing..." /wait "E:\_apbk\Drivers-xp\Audio\setup.exe" -b -s
that install motherboard chipset driver, followed by video and then audio. Lastly, it will restart Windows.
make Gaming smoother
Nowsdays games eat lots of system resources, most NT services can be disabled. So, I write a DOS batch called services_xp.bat:
echo off
echo.
echo Ready to turn off NT services before playing games....
pause
echo .NET Runtime Optimization Service v2.0.50727_X86
pause
net stop clr_optimization_v2.0.50727_32
echo .
echo DHCP Client
pause
net stop dhcp
echo.
echo Distributed Link Tracking Client
pause
net stop TrkWks
echo.
echo DNS Client
pause
net stop Dnscache
echo.
echo Fast User Switching Compatibility
pause
net stop FastUserSwitchingCompatibility
echo.
echo Help and Support
pause
net stop helpsvc
echo.
echo IPSEC Services
pause
net stop PolicyAgent
echo.
echo LightScribeService Direct Disc Labeling Service
pause
net stop LightScribeService
echo.
echo Print Spooler
pause
net stop Spooler
echo.
echo Remote Registry takes very long time to disable itself. mission abort.
pause
rem net stop RemoteRegistry
echo.
echo Server
pause
net stop lanmanserver
echo.
echo SSDP Discovery Service takes very long time to disable itself. mission abort.
pause
rem net stop SSDPSRV
echo.
echo TCP/IP NetBIOS Helper takes very long time to disable itself. mission abort.
pause
rem net stop LmHosts
echo.
echo Themes
pause
net stop Themes
echo.
echo Workstation
pause
net stop lanmanworkstation
echo.
echo All done well.
echo ready to exit
pause
exit
that will automatically perform the disabling task. This really put me smile all day long!
echo off
echo.
echo Ready to turn off NT services before playing games....
pause
echo .NET Runtime Optimization Service v2.0.50727_X86
pause
net stop clr_optimization_v2.0.50727_32
echo .
echo DHCP Client
pause
net stop dhcp
echo.
echo Distributed Link Tracking Client
pause
net stop TrkWks
echo.
echo DNS Client
pause
net stop Dnscache
echo.
echo Fast User Switching Compatibility
pause
net stop FastUserSwitchingCompatibility
echo.
echo Help and Support
pause
net stop helpsvc
echo.
echo IPSEC Services
pause
net stop PolicyAgent
echo.
echo LightScribeService Direct Disc Labeling Service
pause
net stop LightScribeService
echo.
echo Print Spooler
pause
net stop Spooler
echo.
echo Remote Registry takes very long time to disable itself. mission abort.
pause
rem net stop RemoteRegistry
echo.
echo Server
pause
net stop lanmanserver
echo.
echo SSDP Discovery Service takes very long time to disable itself. mission abort.
pause
rem net stop SSDPSRV
echo.
echo TCP/IP NetBIOS Helper takes very long time to disable itself. mission abort.
pause
rem net stop LmHosts
echo.
echo Themes
pause
net stop Themes
echo.
echo Workstation
pause
net stop lanmanworkstation
echo.
echo All done well.
echo ready to exit
pause
exit
that will automatically perform the disabling task. This really put me smile all day long!
keep IE safe and sound
One wonders those free programs that allows one to clear traces especially after using MSIE, either shareware, trial or donationware etc. Well, I write a DOS batch file called rundll32_vista.cmd:
echo off
echo delete IE addons tracking records
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351
echo delete IE miscellaneous files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
echo delete IE password stored
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
echo delete IE autofill form data
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
echo delete IE temporary files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
echo delete IE cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
echo delete IE history list
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
pause
exit
which do the most daunting job ever for me free of downloading them. See the magic works!
echo off
echo delete IE addons tracking records
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351
echo delete IE miscellaneous files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
echo delete IE password stored
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
echo delete IE autofill form data
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
echo delete IE temporary files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
echo delete IE cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
echo delete IE history list
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
pause
exit
which do the most daunting job ever for me free of downloading them. See the magic works!
remove Unused devices
After sometime ago I wonder what devices have been installed via its Automatic Updates in XP or Vista. Normally these hidden device names are not visible in Device Manager and I have to sieve through Windows registry database to locate and verify one by one. Then an idea of DOS scripting came to my mind, so I started to write a batch file:
echo off
set devmgr_show_nonpresent_devices=1
devmgmt.msc
exit
that allows me to view all devices that are commonly displayed by Windows and check its device properties to make wise judgment. Wow, superb!
echo off
set devmgr_show_nonpresent_devices=1
devmgmt.msc
exit
that allows me to view all devices that are commonly displayed by Windows and check its device properties to make wise judgment. Wow, superb!
repair Vista Boot
The other day after installing Windows XP into my system over Vista, the Vista boot manager menu is no longer appearing. So, I write a DOS batch file called nt60repair.bat:-
@echo off
color a
echo Run DAEMON first...
pause
echo.
echo Load vu5384.iso ....
pause
d:
cd boot
bootsect /nt60 c:
echo.
echo Vista Boot Manager repaired...
pause
Because vu5384.iso, a Vista beta, is to be used for repairing, a virtual CDROM utility program has to be first installed and loaded it. This way I don't have to reinstall Vista.
@echo off
color a
echo Run DAEMON first...
pause
echo.
echo Load vu5384.iso ....
pause
d:
cd boot
bootsect /nt60 c:
echo.
echo Vista Boot Manager repaired...
pause
Because vu5384.iso, a Vista beta, is to be used for repairing, a virtual CDROM utility program has to be first installed and loaded it. This way I don't have to reinstall Vista.
Subscribe to:
Posts (Atom)