Powershell - about_Execution_Policies

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • witchdoc
  • Registratie: Juni 2000
  • Laatst online: 02-09 15:54
Ik was wat aant spelen met mijn eigen netwerk en het stoorde me dat mijn Win10 machine geen LLDP verstuurde en dus niet meteen zichtbaar was op de switch.
Hier al snel een oplossing voor gevonden in de Microsoft LLDP driver maar die geeft dan weer enkel het MAC adres door. Ook vrij nutteloos aangezien het MAC adres altijd al duidelijk is op een switch.

Na wat verder zoeken kwam ik https://raspi.github.io/projects/winlldpservice tegen.
Dit is een windows tooltje dat Windows netwerk info via LLDP verstuurd. Precies wat ik zoek dus.

Eenmaal geïnstalleerd kom ik het eerste issue tegen.. het gebruikt powershell voor de configuratie.
Geen probleem, voorbeeld config script zit erbij.

Als ik dat script dan probeer te runnen, komt Windows met het bericht dat dit disabled is voor de veiligheid van mijn systeem.

code:
1
2
3
ile C:\Program Files\WinLLDPService\Configuration.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess


Ik dus braafjes die webpagina gaan lezen zondfer het echt fatsoenlijk te snappen.
Toch wat mee gespeeld en ik kan het doen werken door de ExecutionPolicy aan te passen van 'Restricted' naar 'RemoteSigned'.

Helaas snap ik de impact van dit niet, dus nu dan eindelijk de vraag:
Kan ik dit script op een veilige manier runnen? Kan ik misschien enkel dit script access geven via die Execution_Policies? ....

Alle reacties


Acties:
  • +1 Henk 'm!

  • bdevogt
  • Registratie: Oktober 2007
  • Laatst online: 18-09 22:49
normaal laat ik mijn admin scripts runnen via een batch met een bypass

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\VPNCheck\VPNCheck.ps1'"

hierbij ga je om de policy check heen.

'Iedereen is gelijk, maar sommigen zijn meer gelijk dan anderen',. -George Orwell


Acties:
  • 0 Henk 'm!

  • witchdoc
  • Registratie: Juni 2000
  • Laatst online: 02-09 15:54
bdevogt schreef op zondag 19 juni 2022 @ 12:58:
normaal laat ik mijn admin scripts runnen via een batch met een bypass

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\VPNCheck\VPNCheck.ps1'"

hierbij ga je om de policy check heen.
mm, als ik zoiets aanpas voor dit script ding dan faalt ie.
Kan uiteraard zijn dat ik je commando niet goed heb vertaald :D

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
>PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Program Files\WinLLDPService\Configuration.ps1'"
New-Object : Cannot find type [WinLLDPService.Configuration]: verify that the assembly containing this type is loaded.
At C:\Program Files\WinLLDPService\Configuration.ps1:26 char:11
+ $config = New-Object WinLLDPService.Configuration
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Program Files\WinLLDPService\Configuration.ps1:28 char:1
+ $config.PortDescription.Add("my new port descr..")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WinLLDPService\Configuration.ps1:31 char:1
+ $config.SystemDescription.Add("OS: " + $operatingsystem)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The property 'Separator' cannot be found on this object. Verify that the property exists and can be set.
At C:\Program Files\WinLLDPService\Configuration.ps1:33 char:1
+ $config.Separator = "|"
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Acties:
  • 0 Henk 'm!

  • bdevogt
  • Registratie: Oktober 2007
  • Laatst online: 18-09 22:49
Post je hele script eens?

'Iedereen is gelijk, maar sommigen zijn meer gelijk dan anderen',. -George Orwell


Acties:
  • 0 Henk 'm!

  • Poolkabouter
  • Registratie: Juli 2008
  • Laatst online: 14-08 17:52
Moet Program Files niet tussen dubbele quotes omdat het een spatie bevat? Dus "Program File"?

[ Voor 4% gewijzigd door Poolkabouter op 19-06-2022 18:31 ]


Acties:
  • 0 Henk 'm!

  • Gr4mpyC3t
  • Registratie: Juni 2016
  • Laatst online: 13:21
witchdoc schreef op zondag 19 juni 2022 @ 13:16:
[...]


mm, als ik zoiets aanpas voor dit script ding dan faalt ie.
Kan uiteraard zijn dat ik je commando niet goed heb vertaald :D

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
>PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Program Files\WinLLDPService\Configuration.ps1'"
New-Object : Cannot find type [WinLLDPService.Configuration]: verify that the assembly containing this type is loaded.
At C:\Program Files\WinLLDPService\Configuration.ps1:26 char:11
+ $config = New-Object WinLLDPService.Configuration
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Program Files\WinLLDPService\Configuration.ps1:28 char:1
+ $config.PortDescription.Add("my new port descr..")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WinLLDPService\Configuration.ps1:31 char:1
+ $config.SystemDescription.Add("OS: " + $operatingsystem)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The property 'Separator' cannot be found on this object. Verify that the property exists and can be set.
At C:\Program Files\WinLLDPService\Configuration.ps1:33 char:1
+ $config.Separator = "|"
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Heeft je tool bepaalde configuratie nodig? Lijkt erop dat er bepaalde waardes opgehaald moeten worden zodat er een PSObject gemaakt kan worden voor verder gebruik in die module.

Have you tried turning it off and on again?


Acties:
  • 0 Henk 'm!

  • bdevogt
  • Registratie: Oktober 2007
  • Laatst online: 18-09 22:49
zo te zien roep je een dll aan op regel 26 die hij niet zo kan vinden,
maar zonder je script kunnen we het niet zien.

'Iedereen is gelijk, maar sommigen zijn meer gelijk dan anderen',. -George Orwell


Acties:
  • 0 Henk 'm!

  • witchdoc
  • Registratie: Juni 2000
  • Laatst online: 02-09 15:54
het script mocht dit helpen:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# See homepage (https://raspi.github.io/projects/winlldpservice)for configuration details
# Fetch system specific information

# -- Get Operating system name such as "Win 10 Pro"
$replaceTable = @{
    "Microsoft" = ""
    "Windows" = "Win"
    "Professional" = "Pro"
    "Ultimate" = "Ult"
    "Enterprise" = "Ent"
    "Edition" = "Ed"
    "Service Pack" = "SP"
}

$operatingsystem = (Get-WmiObject Caption -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption)
$replaceTable.GetEnumerator() | ForEach-Object {
    $operatingsystem = $operatingsystem -replace $_.Key, $_.Value
}

$operatingsystem = $operatingsystem.Trim()

# -- Get processor ID
$processorid = (Get-WmiObject ProcessorId -Class Win32_Processor | Select-Object -ExpandProperty ProcessorId)

# Initialize WinLLDPService.Configuration object
$config = New-Object WinLLDPService.Configuration

$config.PortDescription.Add("my new port descr..")

# Add operating system
$config.SystemDescription.Add("OS: " + $operatingsystem)

$config.Separator = "|"

# Must always return WinLLDPService.Configuration object
Return $config

Acties:
  • 0 Henk 'm!

  • bdevogt
  • Registratie: Oktober 2007
  • Laatst online: 18-09 22:49
als ik hem run in mijn ise krijg ik de zelfde melding.

Heb je de service geïnstalleerd van de pagina

https://raspi.github.io/projects/winlldpservice/

daarna zou je op de switch info moeten zien van de pc.

Anders even via de site een comment achter laten voor de developers.

[ Voor 29% gewijzigd door bdevogt op 20-06-2022 11:16 ]

'Iedereen is gelijk, maar sommigen zijn meer gelijk dan anderen',. -George Orwell


Acties:
  • +1 Henk 'm!

  • witchdoc
  • Registratie: Juni 2000
  • Laatst online: 02-09 15:54
bdevogt schreef op maandag 20 juni 2022 @ 11:11:
als ik hem run in mijn ise krijg ik de zelfde melding.

Heb je de service geïnstalleerd van de pagina

https://raspi.github.io/projects/winlldpservice/

daarna zou je op de switch info moeten zien van de pc.

Anders even via de site een comment achter laten voor de developers.
Zoals ik het begrijp is dat scriptje bedoeld om de bijhorende service te configureren.
Die service heb ik dus inderdaad geïnstalleerd.
Het scriptje werkt prima als ik b.v. LocalMachine in RemoteSigned execution policy zet. Dan runt het scriptje perfect vanuit powershell ise en is de LLDP info (uitgezonderd system descr) prima zichtbaar op de switch.

Voor mij is het dus echt een puur execution policy rechten dingetje.
Eerder een randzaak voor hun giothub veronderstel ik, maar goed..zal de vraag toch ook maar eens daar stellen.
Pagina: 1