PowerShell function

Experts:
Good afternoon.  Have a task I'd like to examine automating.  I'm kinda new to powershell, and the below code is just a start, but I can't figure out why the call (in the foreach-object) doesn't see the function.  Is it possible to do this?
$part = gwmi win32_logicaldisk
$part|foreach {. chkacl($_.DeviceID)}

function chkacl {
	param($drive)
	if ($drive.DriveType -eq '3') {
Get-Acl $drive|fl *
	}
}

Open in new window

LVL 2
Just_RCAsked:
Who is Participating?
 
chrismerrittConnect With a Mentor Commented:
Your function needs to go above your script code, powershell processes all lines in order, for example this is right:

Function Badger
{
	Some Function Here
}

#Call Badger Function
Badger

Open in new window


This is not right:

#Call Badger Function
Badger

Function Badger
{
	Some Function Here
}

In VBS the compiler meant it would take care of the Function no matter where it was.

Open in new window

0
 
Just_RCAuthor Commented:
Wait..was pokin' and hopin...here's my 'offical' not working...

$part = gwmi win32_logicaldisk
$part|foreach {chkacl($_.DeviceID)}

function chkacl {
      param($drive)
      if ($drive.DriveType -eq '3') {
Get-Acl $drive|fl *
      }
}
0
 
Just_RCAuthor Commented:
Thanks...I knew it had to be "pilot error".

Thanks a ton.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.