![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Logon Script Builder - ASE I have tried to compile a logon script with ASE and it keeps returning and error, below is the section it points to, it specifically points to the { after function, whats going wrong???? : - function { MapADrive($SharePath, $DriveLetter) #Maps a specified share to a drive letter $net = $(New-Object -Com WScript.Network) $ErrorActionPreference="SilentlyContinue" if ($DriveLetter[-1] -eq ':') { $net.MapNetworkDrive($DriveLetter, "$SharePath") } else { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. Reason: " + $error[0].Exception.Message } } |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Logon Script Builder - ASE Try replacing function { MapADrive($SharePath, $DriveLetter) with function MapADrive($SharePath, $DriveLetter) { The curly bracket had gone walkies. -- Jon "DJYEO" <DJYEO@xxxxxx> wrote in message news:CE761F71-3CB1-4749-91D5-0C5D24FA016D@xxxxxx Quote: >I have tried to compile a logon script with ASE and it keeps returning and > error, below is the section it points to, it specifically points to the { > after function, whats going wrong???? : - > > function { MapADrive($SharePath, $DriveLetter) > #Maps a specified share to a drive letter > $net = $(New-Object -Com WScript.Network) > $ErrorActionPreference="SilentlyContinue" > if ($DriveLetter[-1] -eq ':') > { $net.MapNetworkDrive($DriveLetter, "$SharePath") } > else > { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } > if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. > Reason: " + $error[0].Exception.Message } > } |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Logon Script Builder - ASE Many thanks Jon, that fixed the initial problem but now anothe one has popup, now get a error with "if ((CheckUserGroupMembership", the error states The term 'CheckUserGroupMembership' is not recognized as a cmdlet. Compile script below: - #region Logon Script Builder #True if the user is a member of the specified group if ((CheckUserGroupMembership "Administrators" "True") -eq $true) { MapADrive("\\laptop\c$", "F:") } function MapADrive($SharePath, $DriveLetter){ #Maps a specified share to a drive letter $net = $(New-Object -Com WScript.Network) $ErrorActionPreference="SilentlyContinue" if ($DriveLetter[-1] -eq ':') { $net.MapNetworkDrive($DriveLetter, "$SharePath") } else { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. Reason: " + $error[0].Exception.Message } } function CheckUserGroupMembership($sGroup, $bCheckDomainGroup){ $error.clear() $result = $false $ErrorActionPreference="SilentlyContinue" $sUser = "" if ((Test-Path env:ISEXE) -and ((Get-Item env:ISEXE).Value -eq 1)) { $fullId = Get-Item env:ASEUSERID -ea SilentlyContinue $index = $fullId.indexOf("\") if ($index -ge 0) { $sUser = $fullId.substring($index + 1, $fullId.length - $index - 1) } else { $sUser = $fullId } } else { $sUser = (Get-Item env:USERNAME).Value } if ($bCheckDomainGroup -eq "true") { $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() if ($error) { Write-Host ("Can not check user group membership. Reason: " + $error[0].Exception.Message) } else { $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.SearchRoot = $domain.GetDirectoryEntry() $Searcher.SearchScope = 2 #ADS_SCOPE_SUBTREE $Searcher.Filter = "(&(objectCategory=user)(sAMAccountName=$sUser))" $Searcher.FindAll() | foreach-Object -Process { $Entry = $_.GetDirectoryEntry() $prGroupId = $Entry.primaryGroupId if ( ($sGroup -eq "Domain Users" -and $prGroupId -eq 513) -or ($sGroup -eq "Domain Guests" -and $prGroupId -eq 514) -or ($sGroup -eq "Domain Computers" -and $prGroupId -eq 515) -or ($sGroup -eq "Domain Controllers" -and $prGroupId -eq 516) ) { $result = $true; } elseif ($Entry.MemberOf -ne $null) { foreach ($oGroup in $Entry.MemberOf) { $grpArr = $oGroup.split(",") $fGroup = $grpArr[0] -replace("CN=", "") if ($sGroup -eq $fGroup) { $result = $true break } } } } if ($error) { Write-Host ("Can not check user group membership. Reason: " + $error[0].Exception.Message) } } } else { $oGroupList = Get-WmiObject Win32_Group -filter "name = '$sGroup' and LocalAccount = True" if ($oGroupList -ne $null) { if (($oGroupList.PSBase.GetRelated("Win32_UserAccount") | where-Object { $_.Name -eq "$sUser"}) -ne $null) { $result = $true } } if ($error) { Write-Host ("Can not check user group membership. Reason: " + $error[0].Exception.Message) } } return $result; } #endregion "Jon" wrote: Quote: > Try replacing > > function { MapADrive($SharePath, $DriveLetter) > > with > > function MapADrive($SharePath, $DriveLetter) { > > The curly bracket had gone walkies. > > -- > Jon > > > "DJYEO" <DJYEO@xxxxxx> wrote in message > news:CE761F71-3CB1-4749-91D5-0C5D24FA016D@xxxxxx Quote: > >I have tried to compile a logon script with ASE and it keeps returning and > > error, below is the section it points to, it specifically points to the { > > after function, whats going wrong???? : - > > > > function { MapADrive($SharePath, $DriveLetter) > > #Maps a specified share to a drive letter > > $net = $(New-Object -Com WScript.Network) > > $ErrorActionPreference="SilentlyContinue" > > if ($DriveLetter[-1] -eq ':') > > { $net.MapNetworkDrive($DriveLetter, "$SharePath") } > > else > > { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } > > if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. > > Reason: " + $error[0].Exception.Message } > > } > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Logon Script Builder - ASE Possibly running into one of the little idiosyncracies of Powershell. You need to define your functions before you use them, so in your example try shifting the definition of the function 'CheckUserGroupMembership' to the top. Comparing these 2 may make things clearer. The first example works, but the second errors out with a similar error to the one you're encountering .. #Example 1 Function SayHi {"Hi"} SayHi #Example 2 SayHi2 Function SayHi2 {"Hi"} -- Jon "DJYEO" <DJYEO@xxxxxx> wrote in message news:F137A915-94D8-45D4-A2CD-41210B4B0ACC@xxxxxx Quote: > Many thanks Jon, that fixed the initial problem but now anothe one has > popup, > now get a error with "if ((CheckUserGroupMembership", the error states The > term 'CheckUserGroupMembership' is not recognized as a cmdlet. Compile > script below: - > > #region Logon Script Builder > > #True if the user is a member of the specified group > if ((CheckUserGroupMembership "Administrators" "True") -eq $true) { > MapADrive("\\laptop\c$", "F:") > } > > > > function MapADrive($SharePath, $DriveLetter){ > #Maps a specified share to a drive letter > $net = $(New-Object -Com WScript.Network) > $ErrorActionPreference="SilentlyContinue" > if ($DriveLetter[-1] -eq ':') > { $net.MapNetworkDrive($DriveLetter, "$SharePath") } > else > { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } > if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. > Reason: " + $error[0].Exception.Message } > } > > function CheckUserGroupMembership($sGroup, $bCheckDomainGroup){ > $error.clear() > $result = $false > $ErrorActionPreference="SilentlyContinue" > $sUser = "" > if ((Test-Path env:ISEXE) -and ((Get-Item env:ISEXE).Value -eq 1)) { > $fullId = Get-Item env:ASEUSERID -ea SilentlyContinue > $index = $fullId.indexOf("\") > if ($index -ge 0) > { $sUser = $fullId.substring($index + 1, $fullId.length - $index - 1) } > else > { $sUser = $fullId } > } else { > $sUser = (Get-Item env:USERNAME).Value > } > if ($bCheckDomainGroup -eq "true") { > $domain = > [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() > if ($error) { > Write-Host ("Can not check user group membership. Reason: " + > $error[0].Exception.Message) > } else { > $Searcher = New-Object System.DirectoryServices.DirectorySearcher > $Searcher.SearchRoot = $domain.GetDirectoryEntry() > $Searcher.SearchScope = 2 #ADS_SCOPE_SUBTREE > $Searcher.Filter = "(&(objectCategory=user)(sAMAccountName=$sUser))" > $Searcher.FindAll() | foreach-Object -Process { > $Entry = $_.GetDirectoryEntry() > $prGroupId = $Entry.primaryGroupId > if ( > ($sGroup -eq "Domain Users" -and $prGroupId -eq 513) -or > ($sGroup -eq "Domain Guests" -and $prGroupId -eq 514) -or > ($sGroup -eq "Domain Computers" -and $prGroupId -eq 515) -or > ($sGroup -eq "Domain Controllers" -and $prGroupId -eq 516) ) { > $result = $true; > } > elseif ($Entry.MemberOf -ne $null) { > foreach ($oGroup in $Entry.MemberOf) { > $grpArr = $oGroup.split(",") > $fGroup = $grpArr[0] -replace("CN=", "") > if ($sGroup -eq $fGroup) { > $result = $true > break > } > } > } > } > if ($error) { Write-Host ("Can not check user group membership. Reason: > " + $error[0].Exception.Message) } > } > } else { > $oGroupList = Get-WmiObject Win32_Group -filter "name = '$sGroup' and > LocalAccount = True" > if ($oGroupList -ne $null) { > if (($oGroupList.PSBase.GetRelated("Win32_UserAccount") | where-Object { > $_.Name -eq "$sUser"}) -ne $null) { > $result = $true > } > } > if ($error) { Write-Host ("Can not check user group membership. Reason: " > + $error[0].Exception.Message) } > } > return $result; > } > > > #endregion > > > "Jon" wrote: > Quote: >> Try replacing >> >> function { MapADrive($SharePath, $DriveLetter) >> >> with >> >> function MapADrive($SharePath, $DriveLetter) { >> >> The curly bracket had gone walkies. >> >> -- >> Jon >> >> >> "DJYEO" <DJYEO@xxxxxx> wrote in message >> news:CE761F71-3CB1-4749-91D5-0C5D24FA016D@xxxxxx Quote: >> >I have tried to compile a logon script with ASE and it keeps returning >> >and >> > error, below is the section it points to, it specifically points to the >> > { >> > after function, whats going wrong???? : - >> > >> > function { MapADrive($SharePath, $DriveLetter) >> > #Maps a specified share to a drive letter >> > $net = $(New-Object -Com WScript.Network) >> > $ErrorActionPreference="SilentlyContinue" >> > if ($DriveLetter[-1] -eq ':') >> > { $net.MapNetworkDrive($DriveLetter, "$SharePath") } >> > else >> > { $net.MapNetworkDrive($DriveLetter + ":", "$SharePath") } >> > if ($error) { "Can not map path '$SharePath' to drive '$DriveLetter'. >> > Reason: " + $error[0].Exception.Message } >> > } >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Logon script | PowerShell | |||
| Logon Script Causing Laptops To Hang - Problems in script? | VB Script | |||
| Logon Script | VB Script | |||
| Logon Script - VBScript | Vista General | |||
| Logon Script | Vista General | |||