Solved

PowerShell Send all resullts to one file

Posted on 2016-08-31
7
35 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
  • 4
  • 3
7 Comments
 
LVL 83

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 19

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 83

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 19

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 83

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 19

Author Comment

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

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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