Jean Lalonde Support Forum

Full Version: [Tools-Win] WMI and QAP(script) Part 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
NOTE!
Here is a very simple script, basically for solving three things.
Avoid long parameters in the favourite settings, format the output and write it to a file, make easier to run remote (in my lab).

All parameters in PS can be controlled as input to the script, f.ex: MyScript.ps1 -MyParam SomeValue.
(No more %1 %2 in batch files).

The script
You can run it as any normal application without any input.
Save this as f.ex. test.ps1
Code:
<# .SYNOPSIS #>
Param ( # WMI Class to query.
        $WMIclass="Win32_NetworkAdapterConfiguration",
        # Objects to select in the class.
        $WMIobjects=("Description","MACAddress","IPAddress","DefaultIPGateway","ServiceName","Index"),
        # First part of the file name, can be anything.
        $FilePrefix="Win32_NetworkAdapterConfiguration",
        # If no folder is specified, use the TEMP variable.
        $FileFolder=$env:TEMP,
        # The file name to write the output to.
        $FileName="$FilePrefix-$env:computername.txt"
        )

Clear-Host
Write-Host -ForegroundColor Red "File saved as: $FileFolder\$FileName"
Write-Host -ForegroundColor White -BackgroundColor DarkBlue "Use -FileFolder <path> and/or -FileName <filename> to override"

gcim -ClassName $WMIclass | Select-Object $WMIobjects | Out-File -FilePath $FileFolder\$FileName
gcim -ClassName $WMIclass | Select-Object $WMIobjects | Format-Table -Wrap -AutoSize

Favourite
UserVar:
{pwshopt}=-NoExit -File
{pwshScripts}=C:\MyTools\Scripts\PowerShell\
Type: Application

Basic Settings, Application: pwsh
Adv. Settings, Parameters: {pwshopt} {pwshScripts}test.ps1

Or, we can do some input, f.ex.:

Adv. Settings, Parameters: {pwshopt} {pwshScripts}test.ps1 -FileFolder {Input:Enter path} -FileName {Input:Enter file name}


That's it, we're done..... Smile

Regards,
joeNOR
Here is a tip, the command:

Code:
Get-Help .\test.ps1 -full

shows the parameters and their values without the need to manually open the script in an editor.