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
» Ananse’s Funeral ( Talesoftheworld )
Sat Jan 06, 2018 11:41 am by PhAnt0m

» The Grasshopper And The Toad
Thu Dec 28, 2017 8:37 pm by PhAnt0m

» Why The Crab Has No Head
Sun Dec 24, 2017 3:09 am by PhAnt0m

» The Lazy Townspeople ( Talesoftheworld )
Sun Dec 24, 2017 3:00 am by PhAnt0m

» The Considerate Hunter
Sun Dec 24, 2017 2:42 am by PhAnt0m

» Buy HackGh Proxy Cheat For Free Browsing (Ghana Only)
Mon Dec 18, 2017 6:16 am by PhAnt0m

» [FBT] Proxy testing October 2017
Thu Nov 23, 2017 2:14 pm by willspanner

» Getting a PayPal Account in Ghana
Sat Nov 11, 2017 1:34 pm by saudseidu

» How To Unlock All Alcatel Modems and Phones For Free
Thu Oct 26, 2017 11:34 pm by paah11

» Build your bitcoin wealth with Btccashin matrix revolution 100% legit
Sun Oct 22, 2017 7:46 am by rootboy24

Top posting users this month

Free counters!
Staff Online
Staff Online
Most Online179
Newest Member

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 2

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



To run a script on a remote computer, use the FilePath parameter of the Invoke-Command cmdlet.

Enter the path and file name of the script as the value of the FilePath parameter. The script must reside on the local computer or in a directory that the local computer can access.

The following command runs the ServicesLog.ps1 script on the Server01 remote computer.

invoke-command -computername Server01 -filepath C:\scripts\servicesLog.ps1


To define parameters in a script, use a Param statement. The Param statement must be the first statement in a script, except for comments and any #Requires statements.

Script parameters work like function parameters. The parameter values are available to all of the commands in the script. All of the features of function parameters, including the Parameter attribute and its named arguments, are also valid in scripts.

When running the script, script users type the parameters after the script name.

The following example shows a Test-Remote.ps1 script that has a ComputerName parameter. Both of the script functions can access the ComputerName parameter value.

param ($ComputerName = $(throw "ComputerName parameter is required."))

function CanPing {
$tmp = test-connection $computername -erroraction SilentlyContinue

if (!$?)
{write-host "Ping failed: $ComputerName."; return $false}
{write-host "Ping succeeded: $ComputerName"; return $true}

function CanRemote {
$s = new-pssession $computername -erroraction SilentlyContinue

if ($s -is [System.Management.Automation.Runspaces.PSSession])
{write-host "Remote test succeeded: $ComputerName."}
{write-host "Remote test failed: $ComputerName."}

if (CanPing $computername) {CanRemote $computername}

To run this script, type the parameter name after the script name. For example:

C:\PS> .\test-remote.ps1 -computername Server01

Ping succeeded: Server01
Remote test failed: Server01

For more information about the Param statement and the function parameters see about_Functions and about_Functions_Advanced_Parameters. You can find this additional information in you windows folder , usually on your drive C

Part 3 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