Power shell Newbie

I am so desperate and hoping someone can help. I am currently taking a class that requires me to learn power shell in 2 weeks!! Ugh!! 
I need a script that will allow me to pull like minded files into one file space that I can name . If I was to search all my files that contain the word fire I would like to be able to group them into one file for easy access . I am in danger of failing this class as I have no clue how to write this script. I have read numerous books and online tutorials and not one of them touches on this subject. I am begging for anyones help. Thanks so much 

I am a returning adult student full time job and three kids, my professor seems to think I have all the time in the world to work on this. If anyone could help I would be so very grateful!! 

  • Right now, I feel your pain, but you are really asking folks to do your homework for you and forums / Q&A sites like this one will tell you that we are not a free script/ code writing service. You must show some effort on your own. Show us your code and errors and we'll try and help.

    Not doing so, makes folks less inclined to help. Every once in awhile someone might, but don't bet on it, and you'll often get downvoted, and your query removed/closed off a site.

    Yet, I really would like to know what books/blogs, etc.,  you have been reading, that did not give you what you are after. All of them should have had this stuff in them as it is a very common beginner thing. It's often not possible to a single resource to provide you an exact answer. It will provide the pieces, that you then need to put together for your end results. All use cases can be unique.

    Anyway... because I am a teacher of this stuff myself, and more of the IT PRo / Dev / Security, etc. as well, there lots of videos on Youtube to get you started. We instructors do want folks to learn, but we want you to learn thru self-discovery as well. Sure, there are instructors that can be general jerks, I've had them, but, you work around them and move on or find another.

    https://www.youtube.com/results?search_query=%27beginning+powershell%27

    https://www.youtube.com/results?search_query=%27intermediate+powershell%27

    https://www.youtube.com/results?search_query=%27advanced+powershell%27

    https://www.youtube.com/results?search_query=%27powershell+in+a+month+of+lunches%27

    Your use case is really PowerShell day 1 type of stuff. Managing files and folders.

    https://www.youtube.com/results?search_query=%27powershell+file+management%27

    Yet, this really depends on the file type. You just can't randomly scan any file type. Text files, sure.

    https://www.youtube.com/results?search_query=%27powershell+read+text+file%27

    Yet, when you want to hit MSWord, MSExcel, MS PowerPoint, then you have to learn their object models to open/read them to get anything back. Now, that is intermediate PowerShell stuff.

    https://www.youtube.com/results?search_query=%27powershell+read+word+file%27

    As for your use case...

    If I was to search all my files that contain the word fire I would like to be able to group them into one file for easy access 

    ... It's just a couple of things. Directory lookup and pull match the data. aka recursive file search with a loop with a match for a string.

    https://www.youtube.com/results?search_query=%27powershell+loop+thru+files%27

    https://www.youtube.com/results?search_query=%27powershell+serch+file+content%27

    https://www.youtube.com/results?search_query=%27powershell+if+statement%27

    https://www.youtube.com/results?search_query=%27powershell+matcvh+a+string%27

    https://www.youtube.com/results?search_query=%27powershell+group+file+by+content+match%27

    It's as simple as this, well roughly, as I really want you to get this, knowing there might be an error you'd encounter. For example, you could get errors in the search, if you don't have permissions to the folder or file, and that is expected until you fix that. Fixing those either means using Windows explorer to change the permissions, or PowerShell to change the permissions, and that is a different effort/conversation.

    # Looking at file content, just to see if there are hits
    Get-ChildItem -Path 'd:\temp' -recurse | 
    ForEach{
        
        If (Get-Content -Path $PSItem.FullName | Select-String -Pattern 'txt')
        {
        "Examining $($PSItem.Fullname)"
        "Examined the file and it contains the requested information"
        }
        Else
        {
    <#
            "Examining $($PSItem.Fullname)"
            Write-Warning -Message "Examined the file does not contain the requested information"
    
    #>    }
    }
    
    
    # The taking the learing/info from the above and grouping instead.
    (Get-ChildItem -Path 'd:\temp' -recurse).FullName | 
    ForEach{
        Get-Content -Path $PSItem | 
        Select-String -Pattern 'txt' | 
        Group-Object -Property Pattern
    }
    

    Always use the built-in help files and the examples there first, then videos, then books. Here is a resource I built and give to my students/co-workers, well, anyone who ask me for it after they saw it,  to leverage.

    # Get parameters, examples, full and Online help for a cmdlet or function
    
    # Get a list of all functions
    Get-Command -CommandType Function | 
    Out-GridView -PassThru -Title 'Available functions'
    
    # Get a list of all commandlets
    Get-Command -CommandType Cmdlet | 
    Out-GridView -PassThru -Title 'Available cmdlets'
    
    # Get a list of all functions for the specified name
    Get-Command -Name '*ADGroup*' -CommandType Function | 
    Out-GridView -PassThru -Title 'Available named functions'
    
    # Get a list of all commandlets for the specified name
    Get-Command -Name '*ADGroup**'  -CommandType Cmdlet | 
    Out-GridView -PassThru -Title 'Available named cmdlet'
    
    # get function / cmdlet details
    Get-Command -Name Get-ADUser -Syntax
    (Get-Command -Name Get-ADUser).Parameters.Keys
    Get-help -Name Get-ADUser -Full
    Get-help -Name Get-ADUser -Online
    Get-help -Name Get-ADUser -Examples
    
    Clear-Host
    ((Get-Help -Name Get-NetNeighbor).Examples | 
    Out-String -Stream) -match 'C:\\>|C:\\PS>|PS |PS>') -replace '.*>'
    
    # Get parameter that accepts pipeline input
    Get-Help Get-ADUser -Parameter * | 
    Where-Object {$_.pipelineInput -match 'true'} | 
    Select * 
    
    # List of all parameters that a given cmdlet supports along with a short description:
    Get-Help dir -para * | 
    Format-Table Name, { $_.Description[0].Text } -wrap
    
    
    # Find all cmdlets / functions with a target parameter
    Get-Command -CommandType Function | 
    Where-Object { $_.parameters.keys -match 'credential'} | 
    Out-GridView -PassThru -Title 'Available functions which has a specific parameter'
    
    Get-Command -CommandType Cmdlet | 
    Where-Object { $_.parameters.keys -match 'credential'} | 
    Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'
    
    # Get named aliases 
    Get-Alias | 
    Out-GridView -PassThru -Title 'Available aliases'
    
    # Get cmdlet / function parameter aliases
    (Get-Command Get-ADUser).Parameters.Values | 
    where aliases | 
    select Name, Aliases | 
    Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'
    
    
    # Get Powershell Version info per cmdlet / function
    # Errors displayed can be ignored
    $TargetCmdlets = (Get-Command).Name -match 'process'
    $CmdletSupportedPowerShellVersion = ForEach($Command in $TargetCmdlets) 
    {
        $Command
        (Get-Module (Get-Command -Name $Command).Module) | 
        Select-Object -Property ModuleType,Name,PowerShellVersion,
        @{Name = 'CmdletName_FinctionName';Expression = {$Command}}
    }
    $CmdletSupportedPowerShellVersion | 
    Select-Object -Property ModuleType,Name,CmdletName_FinctionName,PowerShellVersion | 
    Sort-Object -Property Name,PowerShellVersion | 
    Out-GridView -PassThru -Title 'Show list of supported PowerShel version for modules/cmdlet/functions'
    
    <#
    Requires statements need to be the first statements in a script, and they work only for saved scripts.
    #requires statements tell you quickly what a script needs to run.
    #>
    
    #requires -Modules ActiveDirectory
    #requires -Version 3
    #Requires -RunAsAdministrator
    
    
    # All Help topics and locations
    Get-Help about_*
    Get-Help about_Functions
    
    Get-Help about* | Select Name, Synopsis
    
    Get-Help about* | 
    Select-Object -Property Name, Synopsis |
    Out-GridView -Title 'Select Topic' -OutputMode Multiple |
    ForEach-Object { Get-Help -Name $_.Name -ShowWindow }
    
    explorer "$pshome\$($Host.CurrentCulture.Name)"
    
    
    # Show atttribute choices by entering the true name of the type that represents an attribute
    Function Get-AttributeValues
    {
    <#
    .SYNOPSIS
    Get variable attribute values
    
    .DESCRIPTION
    If you ever wondered what your choices are with these attributes, here is how. 
    All you need to know is the true name of the type that represents an attribute. 
    
    PowerShell’s own attributes all reside in the System.Management.Automation 
    namespace.
    
    
    .EXAMPLE
    Get-AttributeValues -Namespace ([System.Management.Automation.ParameterAttribute])
    gav -Namespace ([System.Management.Automation.ParameterAttribute])
    
    .EXAMPLE
    Get-AttributeValues -Namespace ([System.Management.Automation.CmdletBindingAttribute])
    gav -Namespace ([System.Management.Automation.CmdletBindingAttribute])
    
    #>
        [cmdletbinding()]
        [Alias('gav')]
    
        Param
        (
            $Namespace
        )
    
        $Namespace::new() | 
        Get-Member -MemberType *Property | 
        ForEach-Object {
            [PSCustomObject]@{
                Name = $_.Name
                Type = ($_.Definition -split ' ')[0]
            }
        }
    }
    
    
    ### Query Powershell Data Types
    [AppDomain]::CurrentDomain.GetAssemblies() | 
    Foreach-Object { $_.GetExportedTypes() }
    
    # Or 
    
    [psobject].Assembly.GetType(“System.Management.Automation.TypeAccelerators”)::get
    
    # Or
    
    [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get.GetEnumerator() `
    | Sort-Object -Property Key
    
    <#
     Get any .NET types and their static methods from PowerShell. 
     Enumerate all that are currently loaded into your AppDomain.
    #>  
    [AppDomain]::CurrentDomain.GetAssemblies() | 
    foreach { $_.GetTypes() } | 
    foreach { $_.GetMethods() } | 
    where { $_.IsStatic } | 
    select DeclaringType, Name | 
    Out-GridView -PassThru -Title '.NET types and their static methods'
    
    # Instantiate the types using new-object and call instance methods. 
    # You can use get-member on an instance to get the methods on a type.
    
    $Object = [psobject].Assembly.GetType(“System.Management.Automation.TypeAccelerators”)::get
    $Object | Get-Member
    $Object | Get-Member -Static
    $Object.GetType()
    $Object.GetEnumerator()
    
    
    # Review source code.
    Function Show-CmdletSource
    {
        [CmdletBinding()]
    
        [Alias('scs')]
    
        Param
        (
            [string]$CmdletName = (Get-Command -CommandType Cmdlet | 
            Out-GridView -Passthru)
        )
    
        # Get the DLL is it is a compiled cmdlet
        'Getting DLL if the entered cmdlet name is a compiled cmdlet'
        (Get-Command $CmdletName).DLL 
    
        If ((Get-Command -Name $CmdletName).ImplementingType)
        {
           # Do nothing 
        }
        Else
        {
            # Write-Warning -Message "The entered item is not a cmdlet, but a funciton."
            (Get-Command -Name $CmdletName).ScriptBlock
        }
    
        'Getting cmdlet details / source code'
        $metadata = New-Object system.management.automation.commandmetadata (Get-Command $CmdletName)
        [System.management.automation.proxycommand]::Create($MetaData) | 
        out-file "$env:USERPROFILE\Documents\$CmdletName.ps1"
    
        # Choosing an installed Editor to use.
        <#
        $Editor = If (Get-ChildItem -Path "C:\Program Files (x86)\Microsoft VS Code\Code.exe")
        { 'Code.exe' }
        Else { 'Notepad.exe' }
        #>
        # View the cmdlet file
        Start-Process 'Notepad.exe' "$env:USERPROFILE\Documents\$CmdletName.ps1" -Wait
    
        # Remove the file
        Remove-Item -Path "$env:USERPROFILE\Documents\$CmdletName.ps1"
    }
    
    
    Function Show-FunctionSource
    {
        [CmdletBinding()]
    
        [Alias('sfs')]
    
        Param
        (
            [string]$FunctionName = (Get-Command -CommandType Function | 
            Out-GridView -Passthru)
        )
    
        (Get-Command -Name $FunctionName).ScriptBlock `
        | out-file "$env:USERPROFILE\Documents\$FunctionName.ps1"
    
        # View the cmdlet file
        Start-Process 'Notepad.exe' "$env:USERPROFILE\Documents\$FunctionName.ps1" -Wait
    
        # Remove the file
        Remove-Item -Path "$env:USERPROFILE\Documents\$FunctionName.ps1"
    }
    
    
    # Best Practices
    <#
    Windows PowerShell
    https://docs.microsoft.com/en-us/powershell/developer/windows-powershell
    
    Windows PowerShell Best Practices
    https://www.microsoftpressstore.com/store/windows-powershell-best-practices-9780735666498
    
    PowerShell scripting best practices
    https://martin77s.wordpress.com/2014/06/17/powershell-scripting-best-practices
    
    PowerShellPracticeAndStyle
    https://github.com/PoshCode/PowerShellPracticeAndStyle
    
    PowerShell scripting best practices
    https://blogs.technet.microsoft.com/heyscriptingguy/tag/best-practices
    
    Powershell - Recommended coding style
    https://lazywinadmin.com/2011/06/powershell-recommended-coding-style.html
    
    What is the recommended coding style for PowerShell?
    https://stackoverflow.com/questions/2025989/what-is-the-recommended-coding-style-for-powershell
    
    PowerShell 4.0 Best Practices scripts
    This is a place holder for all the scripts from my forthcoming Windows PowerShell 4.0 Best Practices book. Once the book releases, I will upload the 200 scripts to this location -- which is currently referenced in my book. The idea is similiar to the one that I did for the Wi
    https://gallery.technet.microsoft.com/scriptcenter/PowerShell-40-Best-d9e16039
    
    My Scripting Guidelines
    https://social.technet.microsoft.com/Forums/en-US/88b104e4-a187-4312-a7ff-0c6462ec7371/my-scripting-guidelines
    
    Using PSScriptAnalyzer to check your PowerShell code for best practices
    http://mikefrobbins.com/2015/11/19/using-psscriptanalyzer-to-check-your-powershell-code-for-best-practices
    
    PowerShell Standard Library: Build single module that works across Windows PowerShell and PowerShell Core
    https://blogs.msdn.microsoft.com/powershell/2018/08/06/powershell-standard-library-build-single-module-that-works-across-windows-powershell-and-powershell-core
    
    
    Using tools that write code for you or provide sonnets for you to start from
    
    • Scriptomatic2.exe
    • ScriptomaticV2.hta
    • ScriptomaticV2.2.hta
    • EZADScriptomatic.exe
    • PowerShellScriptOMatic v.1.0
    • PowerShellScriptOMaticSetup.msi
    • ADAC - PowerShell History Viewer (already mentioned above)
    
    
    The ADSI Scriptomatic is designed to help you write ADSI scripts; that is, scripts that can be used to manage Active Directory.
    https://www.microsoft.com/en-us/download/details.aspx?id=20460
    
    Scriptomatic 2.2 - with search function
    A very useful for generating WMI scripts, but there are bugs in its date converter function. I have updated it with a new function.
    https://gallery.technet.microsoft.com/scriptcenter/Scriptomatic-21-aka-shame-9cdc28b5
    
    Take Advantage of Scriptomatic 2.0 to Maximize Your WMI Scripting Efforts
    https://www.itprotoday.com/devops-and-software-development/take-advantage-scriptomatic-20-maximize-your-wmi-scripting-efforts
    
    Powershell Scriptomatic
    https://richardspowershellblog.wordpress.com/2008/05/18/powershell-scriptomatic
    
    Two Minute Drill: Scriptomatic 2.0
    https://blogs.technet.microsoft.com/askperf/2009/02/17/two-minute-drill-scriptomatic-2-0
    
    Take advantage of all the samples / examples in the tools
    A Favorite PowerShell ISE Feature: Snippets
    https://blogs.technet.microsoft.com/heyscriptingguy/2016/01/07/a-favorite-powershell-ise-feature-snippets
    
    VbsEdit, the award-winning VBScript editor that dramatically reduces the time you spend writing .VBS scripts
    https://www.vbsedit.com
    
    Creating PowerShell ISE v3 (and later) Code Snippets
    https://www.jonathanmedd.net/2013/11/creating-powershell-ise-v3-and-later-code-snippets.html
    
    Weekend Scripter: The WMI Explorer Tool
    https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/13/weekend-scripter-the-wmi-explorer-tool
    
    Coretech WMI and PowerShell Browser – CTGlobal
    https://blog.ctglobalservices.com/powershell/kaj/coretech-wmi-and-powershell-browser
    
    Snippet Manager 4.01 released
    https://bytecookie.wordpress.com/2015/09/19/snippet-manager-4-01-released
    
    PowerShell Code Manager 6
    https://bytecookie.wordpress.com/powershell-code-manager
    
    SnippetManager & Injector 3 / Code Snippet Manager for ISE, PowerGUI and
    https://gallery.technet.microsoft.com/scriptcenter/SnippetManager-Injector-3-89eaf7a7
    
    
    Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2
    https://blogs.technet.microsoft.com/canitpro/2015/03/04/step-by-step-utilizing-powershell-history-viewer-in-windows-server-2012-r2/
    
    Learning PowerShell with Active Directory Administrative Center (PowerShell History Viewer)
    https://sid-500.com/2017/10/10/learning-powershell-with-active-directory-administrative-center-powershell-history-viewer
    #>