Solved

PowerShell Send all resullts to one file

Posted on 2016-08-31
7
42 Views
Last Modified: 2016-08-31
I am trying to write a simple Powershell script which I can run to query the environment and look for the presence of a directory

Here is what I am looking for as as example:

  $env:COMPUTERNAME ; Test-Path c:\users ;get-date

I would like all results display on the powershell console and append to a file the with each workstation result listed on one line each
0
Comment
Question by:compdigit44
[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
  • 4
  • 3
7 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 41778273
Something like that, or what is it exactly you're planning to do?
"$($ENV:ComputerName);$(Test-Path C:\Users);$(Get-Date)" >>"\\SomeServer\SomeShare\SomeFile.txt"

Open in new window

1
 
LVL 20

Author Comment

by:compdigit44
ID: 41778280
Thank!!!

 Now if I wanted to run this against a list of device but have it report the results to the console and file how would I do that. I would assume I would need WinRM enabled for this.

I am asking since I an inventorying a companies small network which we just took over
0
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 41778316
You only need the admin share.
$Share = 'C$'
$Path = 'Users'
Get-Content C:\Temp\Devices.txt | ForEach-Object {
	Try {
		Get-Item "\\$_\$Share" -ErrorAction Stop | Out-Null
		$Result = Test-Path "\\$($_)\$Share\$Path"
	} Catch {
		$Result = $_.Exception.Message
	}
	"$($_);$($Result);$(Get-Date)" | Tee-Object -FilePath "C:\Temp\SomeFile.txt" -Append
}

Open in new window

1
Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

 
LVL 20

Author Comment

by:compdigit44
ID: 41778324
Thanks so much...

I understand the get-content is for the text file list all devices but I am confused as to the first two lines
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41778329
$Share is the share under which the path is when accessed remotely; for C:\Users, that would be the administrative share C$.
$Path is the path to test against under that share.
A simple
Test-Path "\\$_\C`$\Users"
would lead to false negatives if the machine is turned off or otherwise not accessible.
0
 
LVL 20

Author Comment

by:compdigit44
ID: 41778348
Thanks I will test it.... WinRM is required ino rder to run this correct?
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41778351
Nope; as I said, just the regular admin shares. No remoting involved.
1

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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