HackGh Community Forum

Log in

I forgot my password



Who Is Online?
Guests : 0
Hidden : 0
Registered : 0
Users Online :
Refresh View the whole list

Latest topics
» Build your bitcoin wealth with Btccashin matrix revolution 100% legit
Today at 7:59 am by rootboy24

» What does the "secret code" *#9900# really do to your Android device?
Tue Oct 10, 2017 1:28 pm by chinesta10

» MTN 300GB DATA CHEAT
Tue Sep 26, 2017 1:01 pm by kbasante

» Airtel Sika kokoo promo
Wed Sep 20, 2017 4:07 pm by Dagobert

» Glo Proxy Cheat 2016 Fbt/Cheats By HackGhTeaM
Sat Sep 02, 2017 6:31 am by chinesta10

» AIRTEL FREE BROWSING
Tue Aug 15, 2017 1:20 pm by akokono

» Instagram Account hacked
Sun Aug 06, 2017 7:17 pm by saudseidu

» AIRTEL DATA TRANSFER
Sat Aug 05, 2017 7:22 pm by kbasante

» Watch Free 2CTV on any Vodafone line for the month of July
Thu Aug 03, 2017 2:45 pm by WhIPL4$h

» Tigo subscription cheat testing...
Wed Jul 26, 2017 8:39 am by chinesta10

Top posting users this month
rootboy24
 
WhIPL4$h
 
chinesta10
 



Free counters!
Staff Online
Staff Online
Members2046
Most Online179
Newest Member
BBC alternative

You are not connected. Please login or register

 » Computer Tricks And Technology Tips » Pc ( Windows ) Tips & Downloads » 

How to write and run scripts in Windows PowerShell - Part 1

View previous topic View next topic Go down  Message [Page 1 of 1]

PhAnt0m

avatar
Administrator
Administrator
LONG DESCRIPTION

A script is a plain text file that contains one or more Windows PowerShell commands. Windows PowerShell scripts have a .ps1 file name extension.

Writing a script saves a command for later use and makes it easy to share with others. Most importantly, it lets you run the commands simply by typing the script path and the file name. Scripts can be as simple as a single command in a file or as extensive as a complex program.

Scripts have additional features, such as the #Requires special comment, the use of parameters, support for data sections, and digital signing for security. You can also write Help topics for scripts and for any functions in the script.

HOW TO WRITE A SCRIPT

A script can contain any valid Windows PowerShell commands, including single commands, commands that use the pipeline, functions, and control structures such as If statements and For loops.

To write a script, start a text editor (such as Notepad) or a script editor (such as the Windows PowerShell Integrated Scripting Environment [ISE]). Type the commands and save them in a file with a valid file name and the .ps1 file name extension.

The following example is a simple script that gets the services that are running on the current system and saves them to a log file. The log file name is created from the current date.

$date = (get-date).dayofyear
get-service | out-file "$date.log"

To create this script, open a text editor or a script editor, type these commands, and then save them in a file named ServiceLog.ps1.


HOW TO RUN A SCRIPT

Before you can run a script, you need to change the default Windows PowerShell execution policy. The default execution policy, "Restricted" prevents all scripts from running, including scripts that you write on the local computer. For more information, see about_Execution_Policies.

To run a script, type the full name and the full path to the script file.

For example, to run the ServicesLog script in the C:\Scripts directory, type:

c:\scripts\ServicesLog.ps1

To run a script in the current directory, type the path to the current directory, or use a dot to represent the current directory, followed by a path backslash (.\).

For example, to run the ServicesLog.ps1 script in the local directory, type:

.\ServicesLog.ps1

As a security feature, Windows PowerShell does not run scripts when you double-click the script icon in Windows Explorer or when you type the script name without a full path, even when the script is in the current directory. For more information about running commands and scripts in Windows PowerShell, see about_Command_Precedence.

Part 2 to follow.......


------------------------------------------------



Hacking Is My Religion ..Hackers Inside



[Useful Links]
Free Browsing
Betting Hack
Buy A Website
Reset Your Password
Free Cheat Book
View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum