PS Script to prompt for a computer name to obtain up time information

Good morning everyone and please excuse the interruption.
I found this particular script online that when executed can tell me the uptime of a computer (from the looks of it, it only works on the computer it is run on)
Is there a way to modify the script so it can do the following:
prompt me to enter a computer name
display the uptime of said computer entered
This script says I would need to insert a line with all the computer names i want it to look for, which to me, is too much info.
# Get-Uptime.ps1
# This script will report uptime of given computer since last reboot.
# Pre-Requisites: Requires PowerShell 2.0 and WMI access to target computers (admin access).
# Usage syntax:
# For local computer where script is being run: .\Get-Uptime.ps1.
# For list of remote computers: .\Get-Uptime.ps1 -ComputerList "c:\temp\computerlist.txt"
# Usage Examples:
# .\Get-Uptime.ps1 -Computer ComputerName
# .\Get-Uptime.ps1 -ComputerList "c:\temp\computerlist.txt" | Export-Csv uptime-report.csv -NoTypeInformation
# Last Modified: 3/20/2012
# Created by
# Bhargav Shukla
# http://blogs.technet.com/bshukla
# http://www.bhargavs.com
# DISCLAIMER
# ==========
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#Requires -Version 2.0
param
[Parameter(Position=0,ValuefromPipeline=$true)][string][alias("cn")]$computer,
[Parameter(Position=1,ValuefromPipeline=$false)][string]$computerlist
If (-not ($computer -or $computerlist))
$computers = $Env:COMPUTERNAME
If ($computer)
$computers = $computer
If ($computerlist)
$computers = Get-Content $computerlist
foreach ($computer in $computers)
$Computerobj = "" | select ComputerName, Uptime, LastReboot
$wmi = Get-WmiObject -ComputerName $computer -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem"
$now = Get-Date
$boottime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
$uptime = $now - $boottime
$d =$uptime.days
$h =$uptime.hours
$m =$uptime.Minutes
$s = $uptime.Seconds
$Computerobj.ComputerName = $computer
$Computerobj.Uptime = "$d Days $h Hours $m Min $s Sec"
$Computerobj.LastReboot = $boottime
$Computerobj

i think i understand so instead of the parameter where its reading from a computer list i should remove that and use the calculated properties as a param?
No, the calculated property is only for output. Here's a quick example:
$computerList = Read-Host 'Enter computer name'
foreach ($computer in $computerList) {
Get-WmiObject Win32_OperatingSystem -ComputerName $computer |
Select @{N='ComputerName';E={$computer}},
@{N='LastBootupTime';E={[System.Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime)}},
@{N='Uptime';E={(Get-Date) - ([System.Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime))}}
Don't retire TechNet! -
(Don't give up yet - 13,225+ strong and growing)

Similar Messages

  • Can you make Sysprep on Windows 8.1 and Server 2012 R2 Prompt for a Computer Name

    Hi guys,
    Our Windows 7 Unattend.xml has always made Sysprep prompt for Computer Name. I'm struggling to achieve that with Windows 8.1 and Svr 2012 R2.
    Firstly: Is it still possible?
    Secondly: If so, How?
    Thanks

    OOBE will only hide pages that contain the answers in the XML. So if you want OOBE to prompt for a computer name, make sure your XML does not contain the ComputerName object.

  • Looking for my computer name and mac address.  Where do i find them?

    I think this should be straightforward.  Where would I find my Mac Address and name of my computer?  I want to tether with my phone and need to give my phone this info.
    Thanks in Advance.
    Deb

    Your Computer Name is found in the Sharing preferences at the top. For your MAC address open Network preferences, select your desired port such as Wireless then click on the Advanced button. Click on the Hardware tab. You will find it there.

  • How to programmatically disable prompts for output file names in Acrobat X

    My code to programmatically disable output file names (below) is not working on a Windows 7 64-bit machine using Acrobat Distiller X.  It works perfectly on a Windows XP machine with Acrobat Distiller 8.
    The latest API Reference I was able to find is dated June 2008.  My logic follows this convention.
    I have confirmed that the registry key is updated as specified below.  I have also confirmed that I am able to write to the directory indicated.
    Please provide any suggestions to resolve. 
    Thank You!
    ~Lori
    'Create the Registry Key where Acrobat looks for a file name
            CreateNewRegistryKey HKEY_CURRENT_USER, _
                         "Software\Adobe\Acrobat Distiller\PrinterJobControl"
    'Put the output filename (FilePath) where Acrobat could find it
            SetRegistryValue HKEY_CURRENT_USER, _
                     "Software\Adobe\Acrobat Distiller\PrinterJobControl", _
                     C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.EXE, _
                     T:\PDF Files\Current Week\NFS_Lori,Test.pdf

    I remember seeing that the problem is thunking. A little more specifically, because it's a 32-bit driver but a 64-bit executable, there's a 32-bit system spooler process which will always show up as the EXE name.

  • Prompt for New Folder Name During Running Workflow?

    I've looked everywhere and cant find an answer for this. I'm trying to create an workflow that will copy the pictures I have selected and put them in a new folder inside a folder I've already created. I want the the workflow to prompt me to give a name for the new folder I'm creating. Can it do this?
    Thanks

    Hi Joshua!
    Thanks for your reply. I´m glad, that it works as expected.
    So I will try my best -- as a non nativ english speaker-- to give you a short explanation of what is doing Automator.
    First of all, read the Automator Help. It is good!
    Then, when you create a Workflow, have a look at the Results of every Action (from the Result Button)
    Also there is an inspector, that will allow you to follow the Workflow.
    Most of the Actions based on AppleScript ans Shell Scripts, they work like this:
    Take an Input (if there is one) and return the Output
    In your case:
    Make a new Folder in Folder x
    Result (Output) = Path to Folder
    Show this action when the workflow runs = so you can set the new folder on the run
    Set the Value of a Variable
    The Input is the path to the new Folder, that will be needed later.
    We don´t want to have an Output for the next Action.
    (That would be still the path to the new Folder)
    Get the selected Finder Items
    In the Result they will be listed.
    Copy this items to the new Folder
    We need the path to the new folder, that was created before. So we use the Variable with the stored path
    Spazek

  • Need script to check for duplicate file names when copying a folder

    Hello,
    I am a new applescript user trying to write what I believe should be a simple script. I was planning on using the "add-new item alert" script as a template.
    Basically I have people copying folders of photos into a library folder, but I don't want the Finder to copy the photo if it already exists in the library. The images in the library are organized into subfolders.
    I need a script that will check all the file names in the new folder against all the file names in the library, and NOT add the new one if it already exists.
    If anyone can help it would be greatly appreciated,
    Thanks,
    C

    I have a script that "kind of" works. The only problem I've seen is that it gets confused when filenames contain characters that are fine in Macland but not good in Unixland. Forward slashes are a good example of this.
    In this case I have a folder in my home named "copytest" Inside copytest are two folders:
    Source (containing the images to be added)
    Dest (My existing library of images)
    It also assumes that the folder of images to be added contains no sub-folders. Hope this helps.
    tell application "Finder"
    set theSource to folder "source" of folder "copytest" of home
    set imagesToBeCopied to name of every file of theSource
    end tell
    repeat with theFile in imagesToBeCopied
    try
    if (do shell script "find -r ~/copytest/dest -name " & quoted form of (theFile as string)) is not equal to "" then
    --The file exists. Don't copy it
    else
    --the file doesn't already exist. Copy it.
    end if
    on error
    return "Failed while trying to check for existence of a file"
    end try
    end repeat

  • Prompted for lpadmin group name and password when adding printer

    I was running into a prompt to enter an lpadmin group name and password whenever I tried to do any printing, so I decided to go ahead and reset my printer list. Now I'm trying to add my local printer to the list and I'm still getting the same prompt.
    I found this solution: http://support.apple.com/kb/ts2754
    on the Apple website, but it's not working for me.
    Perhaps it's because I'm unfamiliar with working in Terminal, but I'm entering the text exactly as it's written on the support page
    dseditgroup -o edit -p -a(affected_username) -t user _lpadmin
    with, of course, my username substituted for the "(affected_username)" but I'm getting an error message in Terminal that says:
    syntax error near unexpected token `('
    Any suggestions or help? It would be much appreciated!

    Looking at the command again step 3 says to replace "(affected_username)". Since the parenthesis are included in the quotes try leaving them out as well.

  • Search for a file name corresponding to system time (nearest)

    Hi There
    I have a utility which i is dumping files into the local file system every say 4 hours .Its creating a folder corresponding to Year ie 2002 or 2004 and in that folder whenever that utility dumps data it creates a file (xml file based on the system time ex 131708.xml created at 1:17:09 PM.
    Now my application has to find dynamically the path coresponding to the latest xml file .The utility dumping xml file is running as a separte process.
    Can anyone suggest as to how to do this
    Help appreciated
    Thanks
    Raj

    I have my code which looks something like this :===
    File f = new File("C:/Text/Text Only/Text news feeds/2002");
    System.out.println("Folder Names Inside "+f.toString());
    String s[]=new String[]{};
    s=f.list();
    for(int i=0;i<s.length;i++)
    System.out.println(s);
    This code returns me all the folders inside the year folder say 2002.
    Now i have to iterate only through the latest month/day folder in this list and then select the file which is latest which is named as per the system time.
    The question is how to serach for the closest match with the file name
    Thanks
    Raj

  • Netinstall Image prompt for computer name

    I am wondering how when I am imaging through Netinstall that I can have the image utility prompt for a computer name at image time. Basically I would like to use System Image Utility --> Add a "System Configuration Step" --> prefill the info to join AD but have the person doing the imaging get prompted for the name at image time. How can I achieve this?

    Bump would like to know if anyone else has looked for this functionality.

  • Computer name for the WinPE

    I'm trying to make a tool my technicians can use to create a backup image for an existing machine.
    What I thought of was using a BAT that I could inject into my Boot images and run some really simple DISM command:
    Dism /Capture-Image /ImageFile:D:\%computername%.wim /CaptureDir:C:\ /Name:"Captured Image"
    Problem is the %computername% to name the WIM keeps comming up as MINWINPC.wim. It's not even the MININT-xxxxxx computer name that WinPE generates. 
    Maybe I'm not using the command correctly, but is there a way I can make the computer name something identifiable, like the computer's serial #?

    One way to get around this is to load the registry of the offline computer in WinPE and get the computer name from there. Computer names are stored in HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName and the value ComputerName.
    You can find instructions for loading the offline computer's registry hive here:
    http://superuser.com/questions/636055/how-to-modify-a-computers-offline-registry-from-winpe
    Otherwise, you could have the script prompt for the computer name and the tech can manually enter it in.

  • Computer Name prompt with Country Code

    Using SCCM 2012 R2.. 
    Currently we have 21 global sites indicated by a two digit country code, for example United States US, United Kingdom, GB, Spain ES  etc.....
    We are a Dell shop so we want the serial number as well.
    Our end result should look like this. United States Computer
    <CountryCode>-<Serialnumber>
    US-23GHT54 for example.
    What is the best way to have a drop down or prompt for country code in computer name field when a tech starts the OSD process??

    Hi
    You can have a look at two of my blog post. The first one will show you how to enable Powershell support in your boot images:
    http://www.mimercon.dk/da/easyblog/entry/adding-powershell-support-in-configuration-manager-2012-r2-boot-images
    And the second one will guide you through all the step required to implement a Powershell GUI prompting for a Computer Name if the machine is unknown:
    http://www.mimercon.dk/da/easyblog/entry/prompt-for-computer-name-during-configmgr-2012-r2-os-deployment-1
    I know that this is not exactly what you want but you would "only" need to create your own Powershell GUI where you can select the country code and append the serial number to get your computer name generated. And then you could just follow the
    step in the second post and substitue my Prompt-Computer-Name GUI with your own.
    If you know a bit about about Windows Forms and Powershell it is fairly easy to create even though it might be easy for me to say that :)
    If you want I could create a basic GUI for you but you would have to be specific in how you would like it to look and I would need all the country codes you need in the drop-down box. You can find my e-mail at my web site.

  • Windows XP Machines Always Prompt for Credentials (Exchange 2013, Outlook 2010)

    I am running Exchange 2013 on Server 2012 Datacenter (VM).  Windows 7 clients with Outlook 2010 work fine.  Windows XP clients with Outlook 2010 prompt for credentials (user name and password) each time Outlook is started, and checking the "Remember
    my password" box does not prevent this from happening the next time.  The "Always prompt for logon credentials" checkbox on the "Security" tab of the "More Settings" section of the Exchange account is not checked.  I have found a myriad of posts
    with similar issues, but they all seem to have to do with SBS/Exchange 2007, and I haven't come across something that works as a solution for me.  One suggested certificate issues, and I was having certificate security warnings, but I got that resolved. 
    I am hopefuly that the fact that this only happens on Windows XP will be telling.

    Proxy settings:
    auth_param ntlm program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp
    auth_param ntlm children 50
    auth_param ntlm keep_alive on
    auth_param basic program /usr/lib/squid3/squid_ldap_auth -R \
    -b "DC=domain,DC=local" \
    -D "CN=Squid Proxy,OU=TI,OU=Domain,DC=domain,DC=local" \
    -W passldap \
    -f "sAMAccountName=%s" \
    -h domain.local
    auth_param basic children 20
    auth_param basic realm Domain Internet Proxy
    auth_param basic credentialsttl 8 hours
    external_acl_type ADS children=50 ipv4 ttl=60 %LOGIN /usr/lib/squid3/squid_ldap_group -S -K -b "DC=domain,DC=local" -f "(&(objectclass=person)(sAMAccountName=%v)(memberof =CN=%a,OU=Domain,DC=domain,DC=local))" -D "CN=Squid Proxy,OU=TI,OU=Domain,DC=domain,DC=local" -s sub -W ldappass domain.local
    tks.

  • Safari 5 stopped prompting for file name when downloading.

    Hello,
    On Safari 4, when I clicked a download link, Safari always prompted for a file name, so I could change it before starting downloading, I installed Safari 5 and "this" feature dissapeared. Can anyone help?
    Thank you in advance,
    Alex

    Works for me: Right-click on the Paint.NET download file here. http://www.dotpdn.com/downloads/pdn.html
    It opens a menu. I click Download Linked File As... and change the name. It downloads.
    What experience are you seeing?

  • When I start firefox it asks for my name, password and computer name everytime

    Every time I click on the icon to start Firefox, it asks for my email address and password, then asks for my computer name. I have selected Facebook as my home page but it still asks me this when I go into Firefox. It is really aggravating now, can anything be done as it never used to do this before. Has been doing it now for a few weeks. Thank you.

    You need to enter both serial numbers, first the Aperture 3 upgrade number, then the Aperture 2 number.
    If Aperture does not accept the numbers, see:
    Troubleshooting Professional Application Serial Numbers:
    http://support.apple.com/kb/TS2005
    And if nothing helps, contact Apple with aproof of purchase, see:
    Pro Application Replacement Serial Numbers
    Regards
    Léonie

  • Random characters after computer name

    Hello,
    We have a new issue with our agent deployment since we use MDT to deploy our workstations.
    When computer register to ZCM some random characters appear after computer name, for example:
    Computer name: corporate001
    ZCM computer name: corporate001-741132927c2e6f41b5569a9f9409b983
    Do you have an explaination?
    ZCM Agent is automatically installed after deployment through a .vbs script.
    cscript ZCMscript.vbs
    Code:
    Set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "PreAgentPkg_AgentCompleteDotNet.exe", "-q " & "-x"
    strComputer = "." ' local computer
    strProcess = "Setup.exe"
    Do Until isProcessRunning(strComputer,strProcess)
    WScript.Sleep(5000)
    Loop
    Do While isProcessRunning(strComputer,strProcess)
    WScript.Sleep(5000)
    Loop
    WScript.Quit 0
    ' Function to check if a process is running
    FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName)
    DIM objWMIService, strWMIQuery
    strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
    SET objWMIService = GETOBJECT("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
    isProcessRunning = TRUE
    ELSE
    isProcessRunning = FALSE
    END IF
    END FUNCTION

    Yes, the random number is the "Device GUID".
    In your Example there would already be a device called "corporate001" in your zone.
    The GUID is added since there cannot be two devices with the same name.
    There are reconciliation rules that determine "matches".
    Most likely, your rules rely upon MAC and/or SN and this changed instead of relying upon Workstation Name.
    No one way is "Correct".
    It really comes down to what works for you.
    Most likely a tweak of the rules to rely more upon "Workstation Name" may work best for you since I suspect your devices are in a domain if using MDT, which means the names are unique.

Maybe you are looking for

  • Why is it I can't just buy the new iPhone without needing an upgrade?

    This has been the most bizarre experience I have ever encountered, and it's enough to put me off Verizon and Apple altogether. Yesterday, I went to pick up the new iPhone for myself and my wife, having gotten and email that we were eligible for the E

  • Time Machine, two computers, and one external HD

    Hi. I have a question regarding time machine and laptops. I have an iMac, a Macbook and a WD Mybook external HD. I have time machine setup and working, seemingly well, with the iMac and the external HD. However, I'd also like, from time to time, to b

  • How to Register a Custom Template for Accounts Payable

    How do I register a Custom Template for Accounts Payable?

  • Frozen white screen when using red eye reduction

    Hi, can anyone help when using red eye button on hp mediasmart photo my photo turns white and I loose my cursor, the only thing I can do is control, alt and delete to log me off.  I have a S5206 desktop with factory settings (which I haven't touched

  • WRT110 Disconnects

    Just installed a wrt110 over christmas.  Used an XP system to set it up and had no issues.  Added some HP printers, another XP system, and a new Windows 7 notebook with no problems.  Then added a Vista notebook.  Now it appears everytime my daughter