Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:15:05+00:00 2026-06-03T03:15:05+00:00

I have written a script that is to collect hardware and software information from

  • 0

I have written a script that is to collect hardware and software information from a forrest/domain. I’ve read several posts about running a PS-script from a computer on a server, but I want to do the opposite.

How do you know that a script is “remotely accesible”.
I’ve seen this command beeing used:

Invoke-Command -ComputerName {serverName} –ScriptBlock { commands }

Is there any other alternatives than computername? I’m thinking that this is not exclussive as several computers can have the same name..

This is my script:

try{
    $ConfirmPreference="none"
    $error.clear()
    $erroractionpreference = "silentlycontinue"

    #Gets the date of this day, used as name for XML-file later.    
    $a = get-date -uformat "%Y_%m_%d"

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

    #Gets the path to directory for all saved files and folders
    $scriptpath = Split-Path -parent $myinvocation.MyCommand.Definition

    #PC Serial Number, is used as name for directory containing XML files for this computer.
    $serialnr = gwmi win32_bios | select -Expand serialnumber

    #Creates a folder with the name of the computers hardware serialnumber if it does not exist.
    if(!(Test-Path -path $scriptpath\$serialnr)) {
        New-item -path $scriptpath -name $serialnr -type directory
    }

    #Username
    $username = gc env:username

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

    #Graphic card
    $gpuname = gwmi win32_VideoController | select -Expand Name

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

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

    #Drive    
    $totalspace = 0
    $totalsize = gwmi -Class win32_logicaldisk
    foreach($size in $totalsize) { $totalspace += $size.size }
    $totalspace = "{0:N2}" -f ($totalspace/1Gb) + " GB"

    #Install time for windows OS
    $utctime = get-wmiobject win32_OperatingSystem | select-object -expandproperty installDate
    $installtime = [System.Management.ManagementDateTimeConverter]::ToDateTime($utctime);
    $installtime = Get-Date $installtime -uformat "%d/%m/%Y %X"


    #--------#
    #XML-form
    #--------#
    try{
    $erroractionpreference = "stop"
    $template = "<computer version='1.0'>
        <hardware>
            <serialnumber>$serialnr</serialnumber>
            <systeminfo>
                <name>$siname</name>
                <manufacturer>$simanufacturer</manufacturer>
                <model>$simodel</model>
            </systeminfo>
            <drive>
                <size>$totalspace</size>
            </drive>
            <memory>
                <size>$totalmem</size>
            </memory>
            <gpu>
                <name>$gpuname</name>
            </gpu>
            <cpu>
                <name>$cpuname</name>
                <manufacturer>$cpumanufacturer</manufacturer>
                <id>cpuid</id>
                <numberofcores>$cpucores</numberofcores>
                <addresswidth>$cpuaddresswidth</addresswidth>
            </cpu>
        </hardware>
        <software>
            <user>
                <name>$username</name>
            </user>
            <osinfo>
                <caption></caption>
                <installdate>$installtime</installdate>
                <servicepack></servicepack>
            </osinfo>
        </software>
    </computer>"

    $template | out-File -force $ScriptPath\$serialnr\$a.xml
    $systemroot = [System.Environment]::SystemDirectory
    $xml = New-Object xml
    $xml.Load("$ScriptPath\$serialnr\$a.xml")
    }catch{
    }

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

    #-------Save and get content--------
    $xml.Save("$scriptpath\$serialnr\$a.xml")
    #$new = Get-Content $scriptpath\$serialnr\$a.xml
    #-----------------------------------

    if(!$?){
        "An error has occured"
    }
}catch{
    [system.exception]
    "Error in script: system exception"

}finally{
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:15:06+00:00Added an answer on June 3, 2026 at 3:15 am

    For the -ComputerName parameter, you can use NETBIOS name, IP address, or fully-qualified domain name. For more details, see Invoke-Command on TechNet.

    Seems like your script is “only” saving the data on the machine it is running, you will probably want it to return something in order to be useful with Invoke-Command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a written a script in PHP that reads from data from a
Hey everyone, I have written a script that downloads a zip file from a
I have written a PHP script that checks whether a domain is available for
I have written a script that gets data from solr for which date is
I have written a PHP script that I would like to use on several
So I have a strange question. I have written a script that re-formats data
I have a mechanize script written in python that fills out a web form
I have written a script that on execution lets the user record a message
related (sort of) to this question. I have written a script that will loop
I have written a Perl script that runs as a daily crontab job that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.