Solved

PowerShell Send all resullts to one file

Posted on 2016-08-31
7
26 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now