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.
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
Param ( # WMI Class to query.
        # Objects to select in the class.
        # First part of the file name, can be anything.
        # If no folder is specified, use the TEMP variable.
        # The file name to write the output to.

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

{pwshopt}=-NoExit -File
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

Here is a tip, the command:

Get-Help .\test.ps1 -full

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