Solved

PowerShell Send all resullts to one file

Posted on 2016-08-31
7
36 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 84

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 84

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 84

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 84

Expert Comment

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

Featured Post

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.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A brief introduction to what I consider to be the best editor for PowerShell.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

766 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