Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Question regarding variable

$
0
0

I'm parsing a list of machines to get a list of profiles, and a list of admin shares.

If I check individually, it works.  If I call the functions I created, in the same pass, only the first returns info.

For instance:

Function Get-Shares
{
 param($box)
 $shares=gwmi win32_share -computername $box -erroraction silentlycontinue|?{$_.path -like "*\"}|Select @{n="FullPath";e={"\\{0}\{1}" -f $_.pscomputername,$_.name}}
 "Shares:"
 $shares
}

Function Get-Profiles
{
param($box)
 $reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$box)
 $regkey=$reg.opensubkey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")
 $profiledir=$regkey.getvalue("profilesdirectory")
 $profilepath="\\$box\$profiledir" -replace ":","$"
 $profiles=gci $profilepath -Exclude "Public"|?{$_.psiscontainer}|%{$_.fullname}|%{get-item "$_\ntuser.dat" -force}|select fullname
 "Profiles:"
 $profiles
}


Foreach ($box in gc .\online.txt)
{
 Get-Shares $box
 Get-Profiles $box
{

will list the shares, but not profiles.  And vice-versa if reversed.

If I set $box to one of the machine names and type Get-Shares $box (or just enter the machine name), it works.  Similarly, the same happens with Get-Profiles $box/machine name.

Any idea why this might happen?  It's kind of puzzling.


Viewing all articles
Browse latest Browse all 6937

Trending Articles