Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 Script problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Nobody
Here To Stay

USA
184 Posts
Status: offline

Posted - 06/18/2012 :  6:55:27 PM  Show Profile  Visit Nobody's Homepage  Reply with Quote
Below is part of script that I wrote to audit the software installed on a PC, and return a list of programs that are not part of our standard build.

This seems to be working perfect for about 99% of our systems. I started investigating the few that were not returning results. I found that if I ran the script from my local c:, results were returned as expected. However, when the script is ran from a network share, no results are returned, and no errors occur.

Any ideas?


 $computer = read-host "Computer Name"
 $arryStandardSoftware = get-content -path "StandardSoftware.txt"| Foreach-Object{$_.trim()}
 $AuditResult = (Get-WMIObject -namespace "root\cimv2\sms" -class sms_installedsoftware -computername "$computer"|
                   Select-Object productname|Where-Object{$arryStandardSoftware -notcontains "$($_.productname)"})
 
 $AuditResult

aka - Matt
www.SnowTrek.org

Edited by - Nobody on 06/18/2012 7:16:30 PM

netmarcos
Honorable But Hopeless Addict

USA
2219 Posts
Status: offline

Posted - 06/18/2012 :  7:49:58 PM  Show Profile  Visit netmarcos's Homepage  Click to see netmarcos's MSN Messenger address  Look at the Skype address for netmarcos  Send netmarcos a Yahoo! Message  Reply with Quote
WMI security settings? Without knowing what the wrapper script is doing, it is really hard to say.

Mark M. Webster

Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard

Go to Top of Page

JeffWouters
Here To Stay

Netherlands
147 Posts
Status: offline

Posted - 06/19/2012 :  02:44:14 AM  Show Profile  Visit JeffWouters's Homepage  Click to see JeffWouters's MSN Messenger address  Look at the Skype address for JeffWouters  Reply with Quote
Sounds like an execution policy issue... take a look at this post: http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/04/run-powershell-scripts-stored-on-a-central-file-share.aspx

Greetsz,
Jeff.
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 06/19/2012 :  1:07:57 PM  Show Profile  Visit jhicks's Homepage  Reply with Quote
Sometimes a UNC is treated as an external source so if your policy is RemoteSigned it won't run. But you should get an error telling you that. Are you running this interactively? Via background job? Scheduled Task? We really need to see the command you are trying to run and how.

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

Nobody
Here To Stay

USA
184 Posts
Status: offline

Posted - 06/21/2012 :  4:46:53 PM  Show Profile  Visit Nobody's Homepage  Reply with Quote
While I was out for the last couple of days recoving from minor surgery, it occured to me that the I had added another item to the "standardsoftware.txt" exclusion list. But I didn't add it to the .txt file in the test environment on my local C:

So this morning I remove that one line(Realtek High Definition Audio Driver), and sure enough everything works as expected. I assumed their might be some encoding issue, so I experimented with setting encoding to unicode, ascii, utf8. None of which resolves the issue. I then experimented with removing other lines from the standardsoftware.txt exclusion file, and it appears that removing any line resolves the issue.

Keeping in mind that this script works on most other computers, it isn't logical that it's a problem with this text file, so the issue must be related to the other side of the "-notcontains" operator, which is the WMI objects coming down the pipeline.

As stated before their are no errors, it appears the command completes. IF I try $AuditResult|Get-Member an error occurs.

"Get-Member : No object has been specified to the get-member cmdlet."

If I run the command interactively from a prompt, I've isolated the failure to the Where-Object command.

$AuditResult = (Get-WMIObject -namespace "root\cimv2\sms" -class sms_installedsoftware -computername "$computer"|
Select-Object productname|
Where-Object{$arryStandardSoftware -notcontains "$($_.productname)"})


Any ideas?

aka - Matt
www.SnowTrek.org

Edited by - Nobody on 06/21/2012 4:49:52 PM
Go to Top of Page

Nobody
Here To Stay

USA
184 Posts
Status: offline

Posted - 06/21/2012 :  7:07:23 PM  Show Profile  Visit Nobody's Homepage  Reply with Quote
Ohh dear... I'm going to have to back off the meds. I've got it figured out now. I was expecting $AuditResult to exist even when no results were returned.

aka - Matt
www.SnowTrek.org
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.09 seconds. Snitz Forums 2000