New to Powershell Scripts and need help.

Welcome Forums General PowerShell Q&A New to Powershell Scripts and need help.

Viewing 3 reply threads
  • Author
    Posts
    • #272443
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      I am trying to create a script that I can give to people to collect information off a local PC or remote.</p>
      I want the script to ask for an IP or if left blank get the local PC’s info. Everything seems right, but it doesn’t work :(</p>

      I have a bunch more information I want to collect, but can’t even get a single return. Please HELP! Thanks in advance.

       

       

       

    • #272668
      Participant
      Topics: 5
      Replies: 170
      Points: 656
      Helping Hand
      Rank: Major Contributor

      Seems like a lot of work building a form just to ask for computername.  Why not just Read-Host?  Anyway, when a troubleshot your script it was hanging on:

      $form.Add_Shown({$textBox.Select()})

      So I modified this a little and got it running.  You have a couple logic issues with assigning the computername in the event of null entry.  Also, just because you can ping a computer Test-Connection does not mean you can run Get-WMIObject -computername …..  Get-WMIObject (which is deprecated) uses RPC and ping is ICMP so still may not work.  Get-CIMInstance is the preferred method now.  It uses WinRM.  Anyway, I left that as is.  Here is working code using your script below.

       

    • #272734
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Awesome thanks Mike, yeah after I posted I ran into the WinRM issue as well.  I need to pull a lot more information, but that’s the easy part. I currently have a bat file that does everything using PowerShell, but it has to be copied and ran per box. A co-worker sent me down this rabbit hole telling me a PowerShell script will be much cleaner and be able to run remotely.

      <style></style>

    • #272740
      Participant
      Topics: 5
      Replies: 170
      Points: 656
      Helping Hand
      Rank: Major Contributor

      Your co-worker is right.  A PowerShell script would be much cleaner than a bat file (running PS commands…?) copied to each machine.  If there is lots of data you need to collect, that is fine.  Put it all in one script then call the script for every host you need data from.  For example imagine the following script saved as datacollection.ps1:

      Then to run this script on remote machine(s) use invoke-command like this:

      Then the collected data would be stored in $results and you can filter, sort, export to your hearts desire 🙂

       

      • This reply was modified 1 week, 5 days ago by Mike R..
Viewing 3 reply threads
  • You must be logged in to reply to this topic.