Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell Scripts Won't Run

Posted on 2010-08-26
9
Medium Priority
?
2,259 Views
Last Modified: 2012-05-10
I have the following script that uses PSinfo to gather the software information about a computer and displays it to the screen as output. However it will not run.

I have tired this on two computers, both of which have a 'Remote Signed' execution policy.

Here is the Script:

$computersToQuery = ("Computer1","Computer2","Computer3")

$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
   $psinfoOutput = ./psinfo.exe -s Applications \\$computer

   $foundSoftwareInventory = 0
   $computerName = ""
   foreach ($item in $psinfoOutput) {
      if ($foundSoftwareInventory -eq 1) {
         # Force the results to a string
         # Remove any single quotes which interfere with T-SQL statements
         # Load the result into a hash whereby removing any duplicates
         [string]$softwareInventory[$computerName][$item.Replace("'","")] = ""
      }

      if ($item -like "System information for *") {
         $computerName = $item.Split("\")[2].TrimEnd(":")
      } elseif ($item -eq "Applications:") {
         $foundSoftwareInventory = 1
         $softwareInventory[$computerName] = @{}
      }
   }
}

foreach ($computer in $softwareInventory.Keys) {
   foreach ($softwareItem in $softwareInventory[$computer].Keys) {
      $computer + ":" + $softwareItem
   }
}

0
Comment
Question by:Sleestack90
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:AussieClint
ID: 33539460
Are there any error messages?
Is this a script you have downloaded directly from the internet? If so, the script will be blocked from running. Right click the script and select Properites, on the General tab in the bottom right corner will be an Unblock button. Click the button and click OK. The script should now run. If this is the problem.
0
 
LVL 13

Expert Comment

by:soostibi
ID: 33539598
If it gives output about the installed software, then it is OK. The psinfo.exe gives some information (header, copyright, etc.) that is considered as errors by PowerShell, but I think we can not do much about that, but modify the 5th line to:
   $psinfoOutput = ./psinfo.exe -s Applications \\$computer 2>$null
This supresses that error-like output.
0
 

Author Comment

by:Sleestack90
ID: 33559471
@AussieClint: I copied and pasted it, so there isn't any 'unblock' on this particular file....but good thought


Here are some error messages, which will probably help narrow it down some...sorry I didn't provide these before:


The term './psinfo.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Scripts\Software.ps1:5 char:32
+    $psinfoOutput = ./psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : ObjectNotFound: (./psinfo.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Scripts> software.ps1
The term 'software.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:13
+ software.ps1 <<<<
    + CategoryInfo          : ObjectNotFound: (software.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command software.ps1 was not found, but does exist in the current location. Windows PowerShe
ll doesn't load commands from the current location by default. If you trust this command, instead type ".\software.ps1".
 See "get-help about_Command_Precedence" for more details.
PS C:\Scripts>
0
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 
LVL 6

Expert Comment

by:rwskas
ID: 33577318
./psinfo.exe should be .\psinfo.exe
the command software.ps1 should be .\software.ps1

Looks like its just a syntax issue when running.
0
 

Author Comment

by:Sleestack90
ID: 33579081
@rwskas:

I made the changes you mentioned, but I am still not having any success.

PS C:\Scripts> .\software.ps1
The term './psinfo.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Scripts\Software.ps1:5 char:32
+    $psinfoOutput = ./psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : ObjectNotFound: (./psinfo.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Scripts> .\software.ps1
The term '.\psinfo.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Scripts\Software.ps1:5 char:32
+    $psinfoOutput = .\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : ObjectNotFound: (.\psinfo.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Scripts>
0
 
LVL 6

Accepted Solution

by:
rwskas earned 2000 total points
ID: 33579450
Ok, the error is occuring because it cannot find .\psinfo.exe
So, I would changed .\psinfo.exe with the full path to that executeable:
$psinfoOutput = C:\somepath\somefolder\psinfo.exe -s Applications \\$computer
0
 

Author Comment

by:Sleestack90
ID: 33588139
@rwskas: bingo

Thank you very much, I'm kind of new to this and I tend to get in my own way alot.
0
 

Author Closing Comment

by:Sleestack90
ID: 33588142
Perfect
0
 
LVL 6

Expert Comment

by:rwskas
ID: 33588205
No problem - thats what we are here for! :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question