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!! 

No Data
  • 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.





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


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


    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.


    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.






    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 | 
        If (Get-Content -Path $PSItem.FullName | Select-String -Pattern 'txt')
        "Examining $($PSItem.Fullname)"
        "Examined the file and it contains the requested information"
            "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 | 
        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
    ((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) 
        (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
    Get variable attribute values
    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 
    Get-AttributeValues -Namespace ([System.Management.Automation.ParameterAttribute])
    gav -Namespace ([System.Management.Automation.ParameterAttribute])
    Get-AttributeValues -Namespace ([System.Management.Automation.CmdletBindingAttribute])
    gav -Namespace ([System.Management.Automation.CmdletBindingAttribute])
        $Namespace::new() | 
        Get-Member -MemberType *Property | 
        ForEach-Object {
                Name = $_.Name
                Type = ($_.Definition -split ' ')[0]
    ### Query Powershell Data Types
    [AppDomain]::CurrentDomain.GetAssemblies() | 
    Foreach-Object { $_.GetExportedTypes() }
    # Or 
    # 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
    # Review source code.
    Function Show-CmdletSource
            [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 
            # 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
            [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
    Windows PowerShell Best Practices
    PowerShell scripting best practices
    PowerShell scripting best practices
    Powershell - Recommended coding style
    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
    My Scripting Guidelines
    Using PSScriptAnalyzer to check your PowerShell code for best practices
    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.
    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.
    Take Advantage of Scriptomatic 2.0 to Maximize Your WMI Scripting Efforts
    Powershell Scriptomatic
    Two Minute Drill: Scriptomatic 2.0
    Take advantage of all the samples / examples in the tools
    A Favorite PowerShell ISE Feature: Snippets
    VbsEdit, the award-winning VBScript editor that dramatically reduces the time you spend writing .VBS scripts
    Creating PowerShell ISE v3 (and later) Code Snippets
    Weekend Scripter: The WMI Explorer Tool
    Coretech WMI and PowerShell Browser – CTGlobal
    Snippet Manager 4.01 released
    PowerShell Code Manager 6
    SnippetManager & Injector 3 / Code Snippet Manager for ISE, PowerGUI and
    Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2
    Learning PowerShell with Active Directory Administrative Center (PowerShell History Viewer)

No Data