PowerShell Send all resullts to one file

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
LVL 21
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

compdigit44Author Commented:

 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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

compdigit44Author Commented:
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
$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.
compdigit44Author Commented:
Thanks I will test it.... WinRM is required ino rder to run this correct?
Nope; as I said, just the regular admin shares. No remoting involved.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.