Information Gathering via PowerShell Script Pt. 2
May 13th, 2009
Here is another script that I created while trying to hone my PowerShell skills. It prompts you for the FQDN of the computer that you want to gather information on, asks you whether you want to see the output on the screen or dump it into a text file, and then runs a bunch of WMI queries to get a good general overview of the machine in question.
# Function Definition: fnCompInfoGatherExecute Function fnCompInfoGatherExecute { # Prompt for FQDN of Computer to be Queried "Enter the FQDN of the computer you wish to query." $CompName = Read-Host " " # Prompt for Output Method " " "How would you like the output to be handled?" $MenuTopLevel = ' [1] Display on Screen [2] Output to File [3] Exit Choice' # Define Logic for Top Level Menu switch (Read-Host $MenuTopLevel) { 1 { # Define WMI Information to be Retrieved Get-WmiObject Win32_BIOS -ComputerName "$CompName" Get-WmiObject Win32_ComputerSystem -ComputerName "$CompName" Get-WmiObject Win32_DiskDrive -ComputerName "$CompName" Get-WmiObject Win32_DiskPartition -ComputerName "$CompName" Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName "$CompName" Get-WmiObject Win32_Processor -ComputerName "$CompName" } 2 { # Prompt for Output Path " " "Enter the path to the output file (i.e. C:\Output.txt)." $OutputPath = Read-Host " " # Define WMI Information to be Retrieved Get-WmiObject Win32_BIOS -ComputerName "$CompName" >> "$OutputPath" Get-WmiObject Win32_ComputerSystem -ComputerName "$CompName" >> "$OutputPath" Get-WmiObject Win32_DiskDrive -ComputerName "$CompName" >> "$OutputPath" Get-WmiObject Win32_DiskPartition -ComputerName "$CompName" >> "$OutputPath" Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName "$CompName" >> "$OutputPath" Get-WmiObject Win32_Processor -ComputerName "$CompName" >> "$OutputPath" # Open Output File C:\Windows\notepad.exe "$OutputPath" } 3 {Exit} default {"You have chosen an invalid option"; fnPause; fnADSearchMenu} } } # Call fnCompInfoGatherExecute Function fnCompInfoGatherExecute
Recent Comments