haakonlu
haakonlu

Reputation: 949

Powershell: Save file to standing directory

I'm trying to save an XML file from a powershell script to the standing directory, but after some reading online it seems the possibility's are limited. Anyone knows some code that saves to 'standing directory' instead of this code that saves to a 'full path':

-This code is run after the XML is made and some variables are saved to the XML.

$template | out-File C:\Scripts\XML\info.xml
$systemroot = [System.Environment]::SystemDirectory
$xml = New-Object xml
$xml.Load("C:\Scripts\XML\info.xml")

-This code is run at the very end of the script, after the XML and after some commands that adds information to the XML.

$xml.Save("/info.xml")
Get-Content /info.xml

Alle help is appreciated!

Upvotes: 0

Views: 4979

Answers (1)

CB.
CB.

Reputation: 60956

You can find the Path of your script in this way:

$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition

Then you can use $ScriptPath as path in your script to load or save xml file:

$template | out-File $ScriptPath\info.xml  

Upvotes: 3

Related Questions