Beginner Question :-)

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
treierp
Posts: 7
Last visit: Tue Apr 09, 2024 1:29 am

Beginner Question :-)

Post by treierp »

Good Morning
I'm new to PS and got some start problems...

Look at my module

Code: Select all

Using module ..\..\Helper\OutputFormatter.psm1

Function CollectFirewall
{
	$prefix = "FireWall"
	
	$domainprofile = netsh advfirewall show domainprofile state
	$domainprofile = $domainprofile.GetValue(3).Remove(0, 5).Trim()
	AddHardWare -code ($prefix + "DomainProfile") -value $domainprofile
	
	$privateprofile = netsh advfirewall show privateprofile state
	$privateprofile = $privateprofile.GetValue(3).Remove(0, 5).Trim()
	AddHardWare -code ($prefix + "PrivateProfile") -value $privateprofile
	
	$publicprofile = netsh advfirewall show publicprofile state
	$publicprofile = $publicprofile.GetValue(3).Remove(0, 5).Trim()
	AddHardWare -code ($prefix + "PublicProfile") -value $publicprofile
}

Export-ModuleMember CollectFirewall
And that's what's been created in the run.ps1

Code: Select all

#region Source: Hardware\SpecificCollector\FirewallCollector.psm1
function 
{
	Function CollectFirewall
	{
		$prefix = "FireWall"
		
		$domainprofile = netsh advfirewall show domainprofile state
		$domainprofile = $domainprofile.GetValue(3).Remove(0, 5).Trim()
		AddHardWare -code ($prefix + "DomainProfile") -value $domainprofile
		
		$privateprofile = netsh advfirewall show privateprofile state
		$privateprofile = $privateprofile.GetValue(3).Remove(0, 5).Trim()
		AddHardWare -code ($prefix + "PrivateProfile") -value $privateprofile
		
		$publicprofile = netsh advfirewall show publicprofile state
		$publicprofile = $publicprofile.GetValue(3).Remove(0, 5).Trim()
		AddHardWare -code ($prefix + "PublicProfile") -value $publicprofile
	}
	
	Export-ModuleMember CollectFirewall
}
#endregion Source: FirewallCollector.psm1
As you can see, two times the Function Key Word?
What did I wrong ?

Any help is welcome :-)

Peter
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

How are you creating the second script?

There is not enough information to understand what your issue is.
treierp
Posts: 7
Last visit: Tue Apr 09, 2024 1:29 am

Re: Beginner Question :-)

Post by treierp »

Here's my complete project...

Rename it *.txt -> *.rar
Attachments
SISA.Inventar.txt
(127.16 KiB) Downloaded 103 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

By the way:

To get all network fw profiles: Get-NetConnectionProfile
To get the current active profile: (Get-NetConnectionProfile).NetworkCategory

Each active adapter can be set to a different profile.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

treierp wrote: Thu Aug 30, 2018 12:31 am Here's my complete project...

Rename it *.txt -> *.rar
Sorry but I don't do RAR.

You can upload the folder to the project as a ZIP file. RAR files won't upload and the web server and Windows will trash the TXT file.
treierp
Posts: 7
Last visit: Tue Apr 09, 2024 1:29 am

Re: Beginner Question :-)

Post by treierp »

Here's the Zip File.
Thank's for the hint with the Firewall Profile!
Attachments
SISA.Inventar.zip
(138.32 KiB) Downloaded 100 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

I don't see the issue. What is it that is not working?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

It looks to me like you are using the wrong kind of project for a module. You need to create a "module project".
treierp
Posts: 7
Last visit: Tue Apr 09, 2024 1:29 am

Re: Beginner Question :-)

Post by treierp »

As soon as I start the project (F5) this errors are shown in the Output Window
  1. >> Running (SISA.Inventar.psproj) Project Script...
  2. >> Building (SISA.Inventar) Project...
  3. >> Merging 'Startup.pss' ...
  4. >> Merging 'FirewallCollector.psm1' ...
  5. >> Merging 'MachineCollector.psm1' ...
  6. >> Merging 'OSCollector.psm1' ...
  7. >> Merging 'Globals.ps1' ...
  8. >> Writing 'SISA.Inventar.Run.ps1' ...
  9. >> Platform: V5 64Bit (STA) (Elevated)
  10. SISA.Inventar.Run.ps1: ERROR: At Line: -2 char: 9
  11. ERROR: + function
  12. ERROR: +         ~
  13. ERROR: Missing name after function keyword.
  14. ERROR:
  15. SISA.Inventar.Run.ps1: ERROR: At Line: -2 char: 9
  16. ERROR: + function
  17. ERROR: +         ~
  18. ERROR: Missing name after function keyword.
  19. ERROR:
  20. SISA.Inventar.Run.ps1: ERROR: At Line: -2 char: 9
  21. ERROR: + function
  22. ERROR: +         ~
  23. ERROR: Missing name after function keyword.
  24. ERROR:     + CategoryInfo          : ParserError: (:) [], ParseException
  25. ERROR:     + FullyQualifiedErrorId : MissingNameAfterKeyword
  26. ERROR:
  27.  
  28. *** PowerShell Script finished. ***
  29. >> Execution time: 00:00:01
  30. >> Script Ended
  31.  
And this is the generated 'SISA.Inventar.Run.ps1' File
  1. Using module .\Software\SoftwareCollector.psm1
  2. Using module .\Hardware\HardwareCollector.psm1
  3. Using module .\Helper\LogException.psm1
  4. Using module .\Helper\Setup.psm1
  5. Using module .\Helper\OutputFormatter.psm1
  6. Using module ..\..\Helper\OutputFormatter.psm1
  7. Using module ..\..\Helper\OutputFormatter.psm1
  8. Using module ..\..\Helper\OutputFormatter.psm1
  9. #------------------------------------------------------------------------
  10. # Source File Information (DO NOT MODIFY)
  11. # Source ID: c0439dc0-01c8-4f9a-aa3e-a43f1f38e416
  12. # Source File: C:\DEV\SISA.Inventar\SISA.Inventar\SISA.Inventar.psproj
  13. #------------------------------------------------------------------------
  14. <#
  15.     .NOTES
  16.     --------------------------------------------------------------------------------
  17.      Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.154
  18.      Generated on:       30.08.2018 10:06
  19.      Generated by:       pt
  20.     --------------------------------------------------------------------------------
  21.     .DESCRIPTION
  22.         Script generated by PowerShell Studio 2018
  23. #>
  24.  
  25.  
  26.  
  27. #region Source: Startup.pss
  28. #----------------------------------------------
  29. #region Import Assemblies
  30. #----------------------------------------------
  31. #endregion Import Assemblies
  32.  
  33.  
  34.  
  35. function Main {
  36.    
  37.     #Check the Environment
  38.     Try
  39.     {
  40.         $setupResult = Setup
  41.         If (!$setupResult)
  42.         {
  43.             Write-Error -Message ("The Root Folder" + $global:rootDir + "does not exist or is not accessible!") -Category ObjectNotFound
  44.             Exit
  45.         }
  46.     }
  47.     Catch
  48.     {
  49.         LogException $global:logfilename $_
  50.         Exit
  51.     }
  52.    
  53.     #Read the Software
  54.     Try
  55.     {
  56.         CollectSoftware
  57.         ExportSoftwareList
  58.         WriteErrorLog
  59.     }
  60.     Catch
  61.     {
  62.         LogException $global:Slogfilename $_
  63.     }
  64.    
  65.     #Read the Hardware
  66.     Try
  67.     {
  68.         CollectHardware
  69.         ExportHardwareList
  70.         WriteErrorLog
  71.     }
  72.     Catch
  73.     {
  74.         LogException $global:Hlogfilename $_
  75.     }
  76.    
  77.  
  78.    
  79.     $script:ExitCode = 0
  80. }
  81.  
  82.  
  83.  
  84.  
  85. #endregion Source: Startup.pss
  86.  
  87. #region Source: Hardware\SpecificCollector\FirewallCollector.psm1
  88. function
  89. {
  90.    
  91.    
  92.    
  93.     Function CollectFirewall
  94.     {
  95.         $prefix = "FireWall"
  96.        
  97.         $domainprofile = netsh advfirewall show domainprofile state
  98.         $domainprofile = $domainprofile.GetValue(3).Remove(0, 5).Trim()
  99.         AddHardWare -code ($prefix + "DomainProfile") -value $domainprofile
  100.        
  101.         $privateprofile = netsh advfirewall show privateprofile state
  102.         $privateprofile = $privateprofile.GetValue(3).Remove(0, 5).Trim()
  103.         AddHardWare -code ($prefix + "PrivateProfile") -value $privateprofile
  104.        
  105.         $publicprofile = netsh advfirewall show publicprofile state
  106.         $publicprofile = $publicprofile.GetValue(3).Remove(0, 5).Trim()
  107.         AddHardWare -code ($prefix + "PublicProfile") -value $publicprofile
  108.     }
  109.    
  110.     Export-ModuleMember CollectFirewall
  111.    
  112.    
  113.    
  114.    
  115.    
  116. }
  117. #endregion Source: FirewallCollector.psm1
  118.  
  119. #region Source: Hardware\SpecificCollector\MachineCollector.psm1
  120. function
  121. {
  122.    
  123.     $prefix = "Machine"
  124.    
  125.     function CollectMachine
  126.     {
  127.         $win32ComputerSystem = Get-CimInstance -ClassName Win32_ComputerSystem
  128.        
  129.         AddHardWare -code ($prefix + "Manufacturer") -value $win32ComputerSystem.Manufacturer
  130.         AddHardWare -code ($prefix + "Model") -value $win32ComputerSystem.Model
  131.         AddHardWare -code ($prefix + "Family") -value $win32ComputerSystem.SystemFamily
  132.         AddHardWare -code ($prefix + "Status") -value $win32ComputerSystem.Status
  133.         AddHardWare -code ($prefix + "DNSHostName") -value $win32ComputerSystem.DNSHostName
  134.         AddHardWare -code ($prefix + "Domain") -value $win32ComputerSystem.Domain
  135.         AddHardWare -code ($prefix + "Type") -value $win32ComputerSystem.SystemType
  136.         AddHardWare -code ($prefix + "User") -value $win32ComputerSystem.UserName
  137.        
  138.         $cimBiosElement = Get-CimInstance -ClassName CIM_BIOSElement
  139.         AddHardWare -code ($prefix + "BiosVersion") -value $cimBiosElement.Caption
  140.         AddHardWare -code ($prefix + "BiosSerial") -value $cimBiosElement.SerialNumber
  141.        
  142.         $cimDiskDrive = Get-CimInstance -ClassName CIM_DiskDrive
  143.        
  144.         $x = 0
  145.         ForEach ($drive In $cimDiskDrive)
  146.         {
  147.            
  148.             AddHardWare -code ($prefix + "DiskModel_" + $x) -value $drive.Model
  149.             AddHardWare -code ($prefix + "DiskSerial_" + $x) -value $drive.SerialNumber
  150.             AddHardWare -code ($prefix + "DiskInterface_" + $x) -value $drive.InterfaceType
  151.             AddHardWare -code ($prefix + "DiskSize_" + $x) -value $drive.Size
  152.            
  153.             $x += 1
  154.         }
  155.        
  156.         AddHardWare -code ($prefix + "DiskCount") -value $x
  157.        
  158.         $win32VideoController = Get-CimInstance -ClassName Win32_VideoController
  159.        
  160.         $x = 0
  161.         ForEach ($contoller In $win32VideoController)
  162.         {
  163.             AddHardWare -code ($prefix + "VideoController_" + $x) -value $contoller.Caption
  164.             AddHardWare -code ($prefix + "VideoControllerCurrentVerticalResolution_" + $x) -value $contoller.CurrentVerticalResolution
  165.             AddHardWare -code ($prefix + "VideoControllerCurrentHorizontalResolution_" + $x) -value $contoller.CurrentHorizontalResolution
  166.             AddHardWare -code ($prefix + "VideoControllerStatus_" + $x) -value $contoller.Status
  167.             $x += 1
  168.         }
  169.        
  170.         AddHardWare -code ($prefix + "VideoControllerCount") -value $x
  171.        
  172.         $win32PhysicalMemory = Get-CimInstance -ClassName Win32_PhysicalMemory
  173.        
  174.         $x = 0
  175.         ForEach ($memry In $win32PhysicalMemory)
  176.         {
  177.             AddHardWare -code ($prefix + "MemoryBankLabel_" + $x) -value $memry.BankLabel
  178.             AddHardWare -code ($prefix + "MemoryCaption_" + $x) -value $memry.Caption
  179.             AddHardWare -code ($prefix + "MemoryManufacturer_" + $x) -value $memry.Manufacturer
  180.             AddHardWare -code ($prefix + "MemoryFormFactor_" + $x) -value $memry.FormFactor
  181.             AddHardWare -code ($prefix + "MemoryPartNumber_" + $x) -value $memry.PartNumber
  182.             AddHardWare -code ($prefix + "MemorySerialNumber_" + $x) -value $memry.SerialNumber
  183.             AddHardWare -code ($prefix + "MemoryCapacity_" + $x) -value $memry.Capacity
  184.            
  185.             $x += 1
  186.         }
  187.        
  188.         AddHardWare -code ($prefix + "MemoryCount") -value $x
  189.     }
  190.    
  191.     Export-ModuleMember CollectMachine
  192.    
  193.    
  194.    
  195.    
  196.    
  197. }
  198. #endregion Source: MachineCollector.psm1
  199.  
  200. #region Source: Hardware\SpecificCollector\OSCollector.psm1
  201. function
  202. {
  203.    
  204.     $prefix = "OS"
  205.    
  206.     function CollectOS
  207.     {
  208.         $cimsoftwareLicensingService = Get-CimInstance -ClassName SoftwareLicensingService
  209.         AddHardWare -code ($prefix + "LicenseKey") -value $cimsoftwareLicensingService.OA3xOriginalProductKey
  210.        
  211.         $cimOS = Get-CimInstance -ClassName Win32_OperatingSystem
  212.         AddHardWare -code ($prefix + "Status") -value $cimOS.Status
  213.         AddHardWare -code ($prefix + "Caption") -value $cimOS.Caption
  214.         AddHardWare -code ($prefix + "CodeSet") -value $cimOS.CodeSet
  215.         AddHardWare -code ($prefix + "CountryCode") -value $cimOS.CountryCode
  216.         AddHardWare -code ($prefix + "Locale") -value $cimOS.Locale
  217.         AddHardWare -code ($prefix + "MUILanguages") -value $cimOS.MUILanguages
  218.         AddHardWare -code ($prefix + "OSArchitecture") -value $cimOS.OSArchitecture
  219.         AddHardWare -code ($prefix + "SerialNumber") -value $cimOS.SerialNumber
  220.         AddHardWare -code ($prefix + "Version") -value $cimOS.Version
  221.         AddHardWare -code ($prefix + "InstallDate") -value $cimOS.InstallDate
  222.     }
  223.    
  224.     Export-ModuleMember CollectOS
  225.    
  226.    
  227.    
  228.    
  229.    
  230. }
  231. #endregion Source: OSCollector.psm1
  232.  
  233. #region Source: Globals.ps1
  234. function Invoke-Globals_ps1
  235. {
  236.     $global:errorarray = @()
  237.    
  238.     $global:Harray = @()
  239.    
  240.     $global:Sarray = @()
  241.    
  242.     $global:rootDir = "\\Sisanas06\all_sisa\Inventar\"
  243.     $global:SrootDir = "\\Sisanas06\all_sisa\Inventar\Software"
  244.     $global:HrootDir = "\\Sisanas06\all_sisa\Inventar\Hardware"
  245.     $global:LrootDir = "\\Sisanas06\all_sisa\Inventar\Log"
  246.    
  247.     #general Log File
  248.     $global:logfilename = Join-Path -Path $global:LrootDir -ChildPath "${env:COMPUTERNAME}_$(get-date -f yyyyMMdd).log"
  249.    
  250.     #Hardware Data and Log File
  251.     $global:Hfilename = Join-Path -Path $global:HrootDir -ChildPath "${env:COMPUTERNAME}_$(get-date -f yyyyMMdd).hwi"
  252.     $global:Hlogfilename = Join-Path -Path $global:LrootDir -ChildPath "${env:COMPUTERNAME}_$(get-date -f yyyyMMdd).hwi.log"
  253.    
  254.     #Software Data and Log File
  255.     $global:Sfilename = Join-Path -Path $global:SrootDir -ChildPath "${env:COMPUTERNAME}_$(get-date -f yyyyMMdd).swi"
  256.     $global:Slogfilename = Join-Path -Path $global:LrootDir -ChildPath "${env:COMPUTERNAME}_$(get-date -f yyyyMMdd).swi.log"
  257.    
  258. }
  259. #endregion Source: Globals.ps1
  260.  
  261. #Start the application
  262. Main ($CommandLine)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Beginner Question :-)

Post by jvierra »

You cannot "run" a module. You can create a test project that uses the modules. Also the main module folder has to have a module file that matches the name of the folder.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked