Remoting powershell from server

I'va made a powershell script which collects information and saves it to an XML-file on current computer. I was thinking it was better to directly save the XML to a local server. Q: How is it possible to save XML-file to server? - This is how i'm saving to the same directory as the script: $scriptpath = Split-Path -parent $myinvocation.MyCommand.Definition $template | out-File $ScriptPath\tempXML.xml

Q: Is it possible to run the script from a local server ant then save the XML directly on there server?

This is my script:

 - All variabel names are lowercase
 - All tags in XML are lowercase
Some commands are run and placed directly into the XML (Commands before XML is made). 
Some commands are run after the XML is made and then adds children to specified nodes in the XML.

#Saves the scriptpath to ScriptPath variable(HELPER)
$scriptpath = Split-Path -parent $myinvocation.MyCommand.Definition

#Saves computername to compname variable(HELPER)
$compname = gc env:computername

$brukernavn = gc env:username

#PC Serial Number
$serialnr = gwmi -computer $compname Win32_BIOS | ForEach {$_.SerialNumber}

#System Info
gwmi -computer $compname Win32_ComputerSystem | ForEach {$siname = $_.Name; $simanufacturer = $_.Manufacturer; $simodel = $_.Model}

#Graphic card
gwmi "win32_VideoController" | ForEach-Object {$gpuname = $_.Name}

#Processor Info
gwmi -computer $compname Win32_Processor | ForEach-Object {$cpuname = $_.Name; $cpumanufacturer = $_.Manufacturer; $cpucores = $_.NumberOfCores; $cpuaddresswidth = $_.AddressWidth}

$totalmem = 0
$memsticks = gwmi -Class win32_physicalmemory
foreach ($stick in $memsticks) { $totalmem += $stick.capacity }
$totalmem = [String]$($totalmem / 1gb) + " GB"

#Install time for windows OS
$utctime = get-wmiobject win32_OperatingSystem | select-object -expandproperty installDate
$installtime = [System.Management.ManagementDateTimeConverter]::ToDateTime($utctime);


$template = "<computer version='1.0'>

$template | out-File $ScriptPath\tempXML.xml
$systemroot = [System.Environment]::SystemDirectory
$xml = New-Object xml

#Drive, hardware
$newdrive = (@($[0])
Get-WmiObject -Class Win32_logicaldisk |
ForEach-Object {
    $newdrive = $newdrive.clone()
    $ = [string]$
    $newdrive.volumename = [string]$_.volumename
    $newdrive.size = "{0:N2}" -f ($_.size/1Gb) + " GB"   
    $$newdrive) > $null
$ | where-object {$_.size -eq "0,00 GB" -or $_.volumename -eq ""} | foreach-object {$$_)}

#Memory Info, hardware
$newmemory = (@($[0])
Get-WmiObject -Class WIN32_PhysicalMemory |
ForEach-Object {
    $newmemory = $newmemory.clone()
    $newmemory.PositionInRow = [string]$_.PositionInRow
    $newmemory.datawidth = [string]$_.datawidth
    $newmemory.size = [String]$($_.capacity / 1gb) + " GB"
    $newmemory.devicelocator = $_.devicelocator
    $$newmemory) > $null
$ | where-object {$_.size -eq ""} | foreach-object {$$_)}

#OSInfo, software
$newosinfo = (@($[0])
Get-WmiObject -computer $compname Win32_OperatingSystem | 
ForEach-Object {
        $newosinfo = $newosinfo.clone() 
        [String] $bitversion = gwmi Win32_OperatingSystem osarchitecture;
        $newosinfo.caption = [String]$_.caption
        $newosinfo.serialnumber = [string]$_.serialnumber + " " + $bitversion   
        $newosinfo.servicepack = $_.csdversion
        $$newosinfo) > $null
$ | where-object {$_.caption -eq ""} | foreach-object {$$_)}

#-------Save content----------------


try like this:

$xml.Save("\\$compname\c$\tempXML.xml") # this save on the root (c:\) of remote server

You need local administrative credential to access a c$ share. You can in other way create a share in each server as \\server\myshareforxlm and setting the right permission and do:


Need Your Help

In PyCharm, how to navigate to the top of the file?

python django pycharm

I'm new to PyCharm and haven't been able to figure out what I'm sure is a very simple thing -- what's the key stroke to go to the top of the current file?

How to use a Bootstrap modal to add fields to a form using jQuery

javascript jquery html twitter-bootstrap modal-dialog

I have a form on a Bootstrap modal that captures employment history info. I want to be able, when the user clicks save on the modal the data the user just entered, display on a form.