#Extra string when i call a function

11 messages · Page 1 of 1 (latest)

junior plover
#

Result :

PS C:\Users\Administrateur> C:\Users\Administrateur\Documents\testScript.ps1
Install hardeningKitty and configure it as a persistent PowerShell module
[INFO] Starting installation of HardeningKitty...
[INFO] Execution policy is already set to RemoteSigned
[INFO] Current installed version: 0.9.3
[INFO] Fetching the latest version of HardeningKitty...
[INFO] Latest version detected: 0.9.3
[INFO] HardeningKitty version 0.9.3 is already installed and up-to-date.
\n------------------------------------------------------\n
Find matching lists based on OS Name and OS Version
[INFO] Matching finding list with OS version...
[INFO] Detected OS Version: 21h2
[INFO] Detected OS Version: Get the current OS version 21h2
[INFO] Detected OS Name: microsoft windows server 2022 standard evaluation
[INFO] Formatted OS Name: windows_server_2022
[INFO] Detected OS Version: windows_server_2022
[INFO] Looking for the latest HardeningKitty version in C:\Program Files\WindowsPowerShell\Modules\HardeningKitty
[INFO] Using HardeningKitty module path: C:\Program Files\WindowsPowerShell\Modules\HardeningKitty\0.9.3
[INFO] Using HardeningKitty module path: Get the path of HardeningKitty module C:\Program Files\WindowsPowerShell\Modules\HardeningKitty\0.9.3
[INFO] Checking if lists directory exists at Get the path of HardeningKitty module C:\Program Files\WindowsPowerShell\Modules\HardeningKitty\0.9.3\lists
[ERROR] Lists directory does not exist.
[INFO] Detected OS Version: Get HardeningKitty lists
Impossible d’appeler une méthode dans une expression Null.
Au caractère C:\Users\Administrateur\Documents\testScript.ps1:221 : 13
+         if ($list.ToLower() -match $Os_Version -and $list.ToLower() - ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

[INFO] No matching lists found for OS version: Get the current OS version 21h2
#

[INFO] Detected OS Version: 21h2
[INFO] Detected OS Version: Get the current OS version 21h2

"Get the current OS version" is added

[INFO] Using HardeningKitty module path: C:\Program Files\WindowsPowerShell\Modules\HardeningKitty\0.9.3
[INFO] Using HardeningKitty module path: Get the path of HardeningKitty module C:\Program Files\WindowsPowerShell\Modules\HardeningKitty\0.9.3

"Get the path of HardeningKitty module" is added

worn knoll
#

Never return $null

#

if you want to end early, just return which emits nothing (not explicit null)

#

you can loop over explicit null, which is exactly what's happening when you hit your error

junior plover
#

is it linked with the extra strings ?

worn knoll
#

so find-replace, ```ps
return $null

```ps
return
junior plover
#

TY

worn knoll
#

you can blame PS for having two null's, the one you get when it's explicit like this. And another one you get when a command returns nothing.

junior plover
#

Even if i replace the return $null by return
The extra strings are still here :
[INFO] Detected OS Version: 21h2
[INFO] Detected OS Version: Get the current OS version 21h2

But its kinda weird because OsName isn't affect by this problem :
[INFO] Formatted OS Name: windows_server_2022
[INFO] Detected OS Version: windows_server_2022

worn knoll
#

it should be noted that return is not exclusive in a function. So if I take GetOsVersion that emits the string "Get the current OS version" and the value of $osVersion