milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. Windows
  4. Powershell

Setting the working directory for powershell

Details
Written by: Stanko Milosev
Category: Powershell
Published: 21 February 2015
Last Updated: 21 February 2015
Hits: 3755

To set the working directory for powershell add the following command to your PowerShell profile:

Set-Location c:\scripts

To Create a PowerShell Profile

1. Create a folder in your Documents folder called WindowsPowerShell in my case that is C:\Users\pera.virtualOne\Documents\WindowsPowerShell

2. Create a file called profile.ps1 inside this folder

3. Add any desired initialization commands to this file (Set-Location c:\scripts) and save it

4. Every time you launch PowerShell, the profile script will be executed

Copy / pasted from here.

Use parameter in PowerShell script

Details
Written by: Stanko Milosev
Category: Powershell
Published: 25 August 2014
Last Updated: 21 February 2015
Hits: 3591

If your powershell looks like:

param($myTestParameter)

function TestParameter()
{
	Write-Host "Parameter is: $myTestParameter"
}

Saved as myTest.ps1, for example.

Then to use parameter, call script like:

. .\myTest.ps1 -myTestParameter "Test parameter"

Notice that myTestParameter is without dollar sign, and then you can call function like TestParameter, result should be something like:

Parameter is: Test parameter

Example download from here.