My PowerShell Profile



Here is the script I use for my PowerShell Profile




<#
    Kris Gross PS Profile 
    Email: KrisGross@sccmtst.com
    Website: sccmtst.com
#>

$Shell = $Host.UI.RawUI
$shell.BackgroundColor = "Black"
$shell.ForegroundColor = "Magenta"
$shell.WindowTitle = "PowerShell"
$size = $Shell.BufferSize
$size.width=350
$size.height=10000
$Shell.BufferSize = $size
$size = $Shell.WindowSize
$size.width=150
$size.height=50
$Shell.WindowSize = $size

$host.PrivateData.ErrorForegroundColor = "red"


$ExecutionPolicy = Get-ExecutionPolicy
If ($ExecutionPolicy -ne "Unrestricted") {Set-ExecutionPolicy Unrestricted}

Set-Location "$Env:SystemDrive\"

Function Import-SCCMModule
{
    Set-Location 'F:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\'
    Import-Module .\ConfigurationManager.psd1 -verbose:$false
    Write-Host "Setting location to SCCM Site..."
    Set-Location <SITE CODE>
}

#Get software on a workstation
Function Get-SoftwareInfo
{
        <#

        .SYNOPSIS
        Script to show or export installed software information

        .DESCRIPTION
        The script will display Software ID number, Name, Vendor and Version. 

        .PARAMETER Computer
        With this parameter you cam run this on a remote computer 

        .PARAMETER Export
        Allows you to export the information to a file 

        .PARAMETER ExportFile
        Exportes the software info the a target file, If you do not specify a file then the export will be stored in the script root.

        .NOTES
        Created By: Kris Gross
        Contact: KrisGross@sccmtst.com
        Twitter: @kmgamd
        Version: 2.0.0.0

        .LINK
        http://www.sccmtst.com/2017/04/script-get-softwareinfo.html

    #>


    param(
        [Parameter(Mandatory=$true)]
        $Computer,
        [switch]$Export,
        $ExportFile
        )

    Function Export-SoftwareInfo
    {
        If ($ExportFile) { Get-WmiObject Win32_Product -ComputerName $Computer | Format-List IdentifyingNumber, Name, Vendor, Version | Out-File $ExportFile }
        else 
        {
            $ExportFile = $PSScriptRoot + "\$Computer" + "_Info.txt"
            Get-WmiObject Win32_Product -ComputerName $Computer | Format-List IdentifyingNumber, Name, Version | Out-File $ExportFile
        }
        Write-Host "Exported to: $ExportFile"
    }


    Function Show-SoftwareInfo
    {
        Write-Host "Gathering Software Info on: $Computer"
        Get-WmiObject Win32_Product -ComputerName $Computer | Format-Table IdentifyingNumber, Name, Vendor, Version
    }

    if ($Export) 
    {
        cls
        Write-Host "Exporting Software Info, This can take sometime"
        Export-SoftwareInfo
    }
    else
    {
        cls
        Show-SoftwareInfo
    } 
}

#Get Computer info
Function Get-ComputerInfo
{
        <#
        .SYNOPSIS
        Script to show or export basic system information

        .DESCRIPTION
        The script will display information such as the Computer Name, OS, Memory Information, Disk Information and CPU Information. 

        .PARAMETER Computer
        With this parameter you cam run this on a remote computer 

        .PARAMETER Export
        Tells the Script to export the information

        .PARAMETER ExportFile
        Specify where you want to export the information to export from 

        .EXAMPLE 
        .\Get-ComputerInfo.ps1 -Computer testing
        Gets info about computer testing and shows the info in the command window

        .EXAMPLE
        .\Get-ComputerInfo.ps1 -Computer testing -Export
        Exports the system information to where the script is being exicuted from. 

        .EXAMPLE 
        .\Get-ComputerInfo.ps1 -Computer testing -Export -ExportFile C:\SystemInfo.txt
        Exports the computer info to C:\SystemInfo.txt

        .NOTES
        Created By: Kris Gross
        Email: KrisGross@sccmtst.com
        Twitter: @kmgamd
        Version: 2.0.1.0

        .LINK
        http://sccmtst.com

    #>

    param(
        [Parameter(Mandatory=$true)]
        $Computer,
        [switch]$Export,
        $ExportFile
    )

    $Locked = "No"
    #Gets ths system drive
    $SysDrive = $env:SystemDrive
    #Gets the OS and OS architecture
    $GetOS = Get-WmiObject -class Win32_OperatingSystem -computername $Computer
    foreach($sProperty in $GetOS)
    {
        $OS = $sProperty.Caption
        $OSArchitecture = $sProperty.OSArchitecture
    }
    #Gets memory information
    $Getmemoryslot = Get-WmiObject Win32_PhysicalMemoryArray -ComputerName $computer
    $Getmemory = Get-WMIObject Win32_PhysicalMemory -ComputerName $computer
    $Getmemorymeasure = Get-WMIObject Win32_PhysicalMemory -ComputerName $computer | Measure-Object -Property Capacity -Sum
    #Sets the memory info
    $MemorySlot = $Getmemoryslot.MemoryDevices
    $MaxMemory = $($Getmemoryslot.MaxCapacity/1024/1024)
    $TotalMemSticks = $Getmemorymeasure.count
    $TotalMemSize = $($Getmemorymeasure.sum/1024/1024/1024)
    #Get the disk info
    $GetDiskInfo = Get-WmiObject Win32_logicaldisk -ComputerName $computer -Filter "DeviceID='$env:SystemDrive'"
    #Sets the disk info
    $DiskSize = $([math]::Round($GetDiskInfo.Size/1GB))
    $FreeSpace = $([math]::Round($GetDiskInfo.FreeSpace/1GB))
    $UsedSapce =$([math]::Round($DiskSize-$FreeSpace))
    #Gets CPU info 
    $GetCPU = Get-wmiobject win32_processor -ComputerName $Computer
    #Sets the CPU Name
    $CPUName = $GetCPU.Name
    $CPUManufacturer = $GetCPU.Manufacturer
    $CPUMaxClockSpeed = $GetCPU.MaxClockSpeed

    $OSBuildNumber = (Get-WmiObject Win32_OperatingSystem -ComputerName $Computer).BuildNumber 

    $ComputerModel = (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer).Model


    $LoggedOnUser = (Get-WmiObject win32_computersystem -ComputerName $Computer).Username

    $getLockedStart = If (Get-Process logonui -ComputerName $Computer) {$Locked = "Yes"}

    $SerialNumber = (Get-WmiObject win32_bios -ComputerName $Computer).SerialNumber

    function Show-SystemInfo
    {
        Write-Host "_____________________________________________"
        Write-Host ""
        Write-Host "Computer Name: $Computer"
        Write-Host ""
        Write-Host "Serial Number: $SerialNumber"
        Write-Host ""
        Write-Host "Logged In users: $LoggedOnUser "
        Write-Host ""
        Write-Host "Computer is Locked: $Locked "
        Write-Host ""
        Write-Host "Computer Model: $ComputerModel"
        Write-Host ""
        Write-Host "OS: $OS"
        Write-Host ""
        Write-Host "Build Number: $OSBuildNumber"
        Write-Host ""
        Write-Host "OS Architecture: $OSArchitecture"
        Write-Host "_____________________________________________"
        Write-Host ""
        Write-Host "Memory Slots: $MemorySlot"
        Write-Host ""
        Write-Host "Max Memory Supported (GB): $MaxMemory"
        Write-Host ""
        Write-Host "Total Slots used: $TotalMemSticks"
        Write-Host ""
        Write-Host "Total Memory Installed (GB): $TotalMemSize"
        Write-Host "_____________________________________________"
        Write-Host ""
        Write-Host "System Drive: $Sysdrive"
        Write-Host ""
        Write-Host "Disk Size (GB): $DiskSize"
        Write-Host ""
        Write-Host "Free Disk Space (GB): $FreeSpace"
        Write-Host ""
        Write-Host "Used Disk Space (GB): $UsedSapce"
        Write-Host "_____________________________________________"
        Write-Host ""
        Write-Host "CPU: $CPUName"
        Write-Host ""
        Write-Host "CPU Manufacturer: $CPUManufacturer"
        Write-Host ""
        Write-Host "CPU Max Clock Speed: $CPUMaxClockSpeed"
        Write-Host "_____________________________________________"
        Write-Host ""
    }

    function Export-SystemInfo
    {
        $SystemInfo=@(
        "_____________________________________________"
        ""
        "Computer Name: $Computer"
        ""
        "Serial Number: $SerialNumber"
        ""
        "Logged In users: $LoggedOnUser "
        ""
        "Computer is Locked: $Locked "
        ""
        "Computer Model: $ComputerModel"
        ""
        "OS: $OS"
        ""
        "Build Number: $OSBuildNumber"
        ""
        "OS Architecture: $OSArchitecture"
        "_____________________________________________"
        ""
        "Memory Slots: $MemorySlot"
        ""
        "Max Memory Supported (GB): $MaxMemory"
        ""
        "Total Slots used: $TotalMemSticks"
        ""
        "Total Memory Installed (GB): $TotalMemSize"
        "_____________________________________________"
        ""
        "System Drive: $Sysdrive"
        ""
        "Disk Size (GB): $DiskSize"
        ""
        "Free Disk Space (GB): $FreeSpace"
        ""
        "Used Disk Space (GB): $UsedSapce"
        "_____________________________________________"
        ""
        "CPU: $CPUName"
        ""
        "CPU Manufacturer: $CPUManufacturer"
        ""
        "CPU Max Clock Speed: $CPUMaxClockSpeed"
        "_____________________________________________"
        ""
        )
        If ($ExportFile) { $SystemInfo | Out-File -FilePath $ExportFile }
        else 
        {
            $ExportFile = $PSScriptRoot + "\$Computer" + "_Info.txt"
            $SystemInfo | Out-File -FilePath $ExportFile
        }
        Write-Host "Exported to: $ExportFile"

        
    }

    if ($Export) 
    {
        cls
        Write-Host "Exporting System Info"
        Export-SystemInfo
    }
    else
    {
        cls
        Write-Host "System Info"
        Show-SystemInfo
    }
}

#Create a SCCM collection
Function Create-SCCMCollection
{
    <#
    .SYNOPSIS
    Creates a SCCM Device Collection

    .DESCRIPTION
    Creates a SCCM Device Collection from imput or a list of names in a text file and allows you to set the refresh type

    .PARAMETER CollectionName
    Name of the collection you want to create 

    .PARAMETER CollectionsFile
    Use this parameter to specify a list of collection names to create, must be full file path

    .PARAMETER LimitingCollection
    The Collection you want to limmit the collection members from

    .PARAMETER LoadLocal
    When used will load the Powershell Module from the local system rather then the server

    .PARAMETER SiteServer
    Set the SCCM Site Server

    .PARAMETER SiteCode
    Sets the SCCM Site Code

    .PARAMETER ScheduleType
    Weeks - Sets the Collection to update every x weeks on a spesific days of the week
    Days - Sets the Collection to update every x days
    Hours - Sets the Collection to update every x Hours
    Minutes - Sets teh Collection to update every x Minutes
    Continuous - sets the Collection to update Incrementally

    .EXAMPLE
    Create-Collection.ps1 -SiteServer -Collctionname "Testing Collection" SRV-SCCM -SiteCode MSN -LimmitingCollection "All Desktops" -ScheduleType "Hours"
    Creates a Collection Named Testing Collection with alimmiting Collection of All Desktops that will refresh hourly. 

    .NOTES
    Created By: Kris Gross
    Email: KrisGross@jackofalltech.org
    Twitter: @kmgamd
    Version: 1.0.0.0

    .LINK
    http://sccmtst.com

    #>

    Param(  
            $CollectionName,
            $CollectionsFile,
            [Parameter(Mandatory=$True)]
            $LimitingCollection,
            [Parameter(Mandatory=$True)]
            $SiteServer,
            [Parameter(Mandatory=$True)]
            $SiteCode,
            [Parameter(Mandatory=$True)]
            [ValidateSet('Weeks','Days','Hours','Minutes','Continuous')]
            [string]$ScheduleType 
            )
    #checks to see if CollectionName and CollectionsFile are both being used 
    if (($CollectionName) -and ($CollectionsFile)) {Write-Error "Cannot use both CollectionName and CollectionsFile paramiters"}

    #Sets the Schedule based on the ScheduleType parameter
    If ($Scheduletype -eq "Hours") 
    {   
        $Hours = Read-Host "How many hourse between refreshe"
        $Schedule = New-CMSchedule -RecurInterval Hours -RecurCount $Hours
    }

    If ($Scheduletype -eq "Days") 
    {   
        $Days = Read-Host "How many days between refreshe"
        $Schedule = New-CMSchedule -RecurInterval Days -RecurCount $Days
    }

    If ($Scheduletype -eq "Weeks") 
    {   
        $DayOfWeek = Read-Host "Day of the week for reshresh"
        $WeeksBetween = Read-Host "Weeks between refresh"
        $Schedule = New-CMSchedule -Start "01/01/2014 9:00 PM" -DayOfWeek $DayOfWeek -RecurCount $WeeksBetween
    }

    If ($Scheduletype -eq "Minutes") 
    {   
        $Minutes = Read-Host "How many minutes between refreshe"
        $Schedule = New-CMSchedule -RecurInterval Minutes -RecurCount $Minutes
    }
    #If ether the CollectionName or CollectionsFile parameter are used then will run
    if ((!($CollectionName)) -or (!($CollectionsFile)))
    {
            If ($CollectionsFile)
            {
                $CollectionsFromFile = Get-Content "$CollectionsFile"
                If ($ScheduleType -eq "Continuous")
                {
                    Foreach ($Collection in ($CollectionsFromFile))
                    {
                        New-CmDeviceCollection -Name "$Collection" -LimitingCollectionName "$LimitingCollection" -RefreshType Continuous
                    }
                }
                else 
                {
                    Foreach ($Collection in ($CollectionsFromFile))
                    {
                        New-CmDeviceCollection -Name "$Collection" -LimitingCollectionName "$LimitingCollection" -RefreshSchedule $Schedule
                    }
                }
            }

            IF (!($CollectionsFile))
            {
                If ($ScheduleType -eq "Continuous") 
                {
                    New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshType Continuous
                }       
                else 
                {
                    New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshSchedule $Schedule
                }
            }
    }
    #Changes the location back to where the script was ran from
    Set-Location $PSScriptRoot
}

#lock Local machine
Function llm
{

    $signature = @"  
        [DllImport("user32.dll", SetLastError = true)]  
        public static extern bool LockWorkStation(); 
"@  
        $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru  

        $LockWorkStation::LockWorkStation()|Out-Null
}

#Copy Larg data
Function CopyTool
{
        <#
    .SYNOPSIS
    This script is used to perform large copy jobs

    .DESCRIPTION
    The script provides you a GUI to enter a source and destination for your copy process. The target and destination should be folders,
    the script will copy the content of the source folder into the destination folder.

    .NOTES
    Created By: Kris Gross
    Contact: Krisgross@sccmtst.com
    Twitter: @kmgamd

    .LINK
    http://www.sccmtst.com/
    #>

    Function Generate-Form 
    {
        #Needed for the form to show
        Add-Type -AssemblyName System.Windows.Forms
        Add-Type -AssemblyName System.Drawing
        $tooltip = New-Object System.Windows.Forms.ToolTip
        $Form = New-Object System.Windows.Forms.Form
        $Form.Size = New-Object System.Drawing.Size(660,510)
        $Form.Text = "CopyTool - V 3.0.0.0"
        $Form.StartPosition = "CenterScreen"
        $Form.MinimizeBox = $False
        $Form.MaximizeBox = $False
        $Form.SizeGripStyle = "Hide"

        #Display popup help 
        $ShowHelp={
            Switch ($this.name) 
            {
                "CheckBoxLog"  {$tip = "Create a log file"}
                "Source" {$tip = "Source folder you want to copy"}
                "Destination" {$tip = "Where you want the source folder content to be copied to"}
                "FSOnlyCheckBox" {$tip = "Check this box to only copy the folder structure, No files will be copied"}
                "ExcludeEmptyFolders" {$tip = "Exclude empty folders"}
                "MOVECheckBox" {$tip = "Moves all files and folders from source to destination"}
                "xfcheckbox" {$tip = "Allows you to specify files to be excluded, us * as a wildcard"}
            }
            $tooltip.SetToolTip($this,$tip)
        } 
        
        #sets the help button
        $HelpButton = New-Object System.Windows.Forms.Button
        $HelpButton.Location = New-Object System.Drawing.Point(15,145)
        $HelpButton.Size = New-Object System.Drawing.Size(220,23)
        $HelpButton.Text = "HELP"
        $HelpButton.Add_Click({Click_Help})

        #sets the donate button
        $DonateButton = New-Object System.Windows.Forms.Button
        $DonateButton.Location = New-Object System.Drawing.Point(570,0)
        $DonateButton.Size = New-Object System.Drawing.Size(75,20)
        $DonateButton.Text = "Donate"
        $DonateButton.Add_Click({Click_Donate})

        #sets the copy button
        $CopyButton = New-Object System.Windows.Forms.Button
        $CopyButton.Location = New-Object System.Drawing.Point(15,90)
        $CopyButton.Size = New-Object System.Drawing.Size(100,50)
        $CopyButton.Name = "Copy Button"
        $CopyButton.Text = "Start"
        $CopyButton.BackColor = "ForestGreen"
        $CopyButton.Add_Click({Click_Copy})

        #sets the stop button
        $StopButton = New-Object System.Windows.Forms.Button
        $StopButton.Location = New-Object System.Drawing.Point(135,90)
        $StopButton.Size = New-Object System.Drawing.Size(100,50)
        $StopButton.Name = "Copy Stop"
        $StopButton.Text = "Stop"
        $StopButton.BackColor = "IndianRed"
        $StopButton.Add_Click({Click_Stop})

        #label for source box
        $SourceBoxLabel = New-Object System.Windows.Forms.Label
        $SourceBoxLabel.Location = New-Object System.Drawing.Point(15,10)
        $SourceBoxLabel.Size = New-Object System.Drawing.Size(280,13) 
        $SourceBoxLabel.Text = "Source:"

        #source box
        $SourceBox = New-Object System.Windows.Forms.TextBox
        $SourceBox.Name = "Source"
        $SourceBox.Location = New-Object System.Drawing.Size(15,25) 
        $SourceBox.Size = New-Object System.Drawing.Size(250,25)
        $SourceBox.Font = "Courier New"
        $SourceBox.Text = $Source
        $SourceBox.add_MouseHover($ShowHelp)

        #Browse button for source 
        $BrowseSourceButton = New-Object System.Windows.Forms.Button
        $BrowseSourceButton.Location = New-Object System.Drawing.Point(280,25)
        $BrowseSourceButton.Size = New-Object System.Drawing.Size(75,20)
        $BrowseSourceButton.Text = "Browse"
        $BrowseSourceButton.Add_Click({Click_BrowseSource})

        #Destination label 
        $DestinationBoxLabel = New-Object System.Windows.Forms.Label
        $DestinationBoxLabel.Location = New-Object System.Drawing.Point(15,50)
        $DestinationBoxLabel.Size = New-Object System.Drawing.Size(280,13) 
        $DestinationBoxLabel.Text = "Destination:"

        #Destination Box 
        $DestinationBox = New-Object System.Windows.Forms.TextBox 
        $DestinationBox.Name = "Destination"
        $DestinationBox.Location = New-Object System.Drawing.Size(15,65) 
        $DestinationBox.Size = New-Object System.Drawing.Size(250,25)
        $DestinationBox.Font = "Courier New"
        $DestinationBox.Text = $Destination
        $DestinationBox.add_MouseHover($ShowHelp)

        #Browse button for destination
        $BrowseDestinationButton = New-Object System.Windows.Forms.Button
        $BrowseDestinationButton.Location = New-Object System.Drawing.Point(280,65)
        $BrowseDestinationButton.Size = New-Object System.Drawing.Size(75,20)
        $BrowseDestinationButton.Text = "Browse"
        $BrowsedestinationButton.Add_Click({Click_BrowseDestination})

        #Output box
        $outputBox = New-Object System.Windows.Forms.textBox 
        $outputBox.Location = New-Object System.Drawing.Size(15,175) 
        $outputBox.Size = New-Object System.Drawing.Size(610,290)
        $outputBox.BackColor = "Black"
        $outputBox.forecolor = "YellowGreen"
        $outputBox.MultiLine = $True
        $outputBox.ReadOnly = $True
        $outputBox.Scrollbars = "Both"
        $outputBox.Font = "Courier New"

        #Check box for creating a log file
        $checkboxLog = New-Object System.Windows.Forms.checkbox
        $checkboxLog.Name = "CheckBoxLog"
        $checkboxLog.Location = New-Object System.Drawing.Size(5,15)
        $checkboxLog.Size = New-Object System.Drawing.Size(45,20)
        $checkboxLog.Checked=$False
        $CheckBoxLog.add_MouseHover($ShowHelp)
        $checkboxLog.Text = "Log"

        #Check box for file structure only 
        $FSOnlyCheckBox = New-Object System.Windows.Forms.checkbox
        $FSOnlyCheckBox.Name = "FSOnlyCheckBox"
        $FSOnlyCheckBox.Location = New-Object System.Drawing.Size(50,15)
        $FSOnlyCheckBox.Size = New-Object System.Drawing.Size(90,20)
        $FSOnlyCheckBox.Checked=$False
        $FSOnlyCheckBox.add_MouseHover($ShowHelp)
        $FSOnlyCheckBox.Text = "FS Only"

        #Check box for the S switch, used to exclude empty folders
        $ScheckBox = New-Object System.Windows.Forms.checkbox
        $ScheckBox.Name = "ExcludeEmptyFolders"
        $ScheckBox.Location = New-Object System.Drawing.Size(5,35)
        $ScheckBox.Size = New-Object System.Drawing.Size(45,20)
        $ScheckBox.Checked=$False
        $ScheckBox.add_MouseHover($ShowHelp)
        $ScheckBox.Text = "/S"
        
        #Check box for moving source to destination
        $MoveCheckBox = New-Object System.Windows.Forms.checkbox
        $MoveCheckBox.Name = "MOVECheckBox"
        $MoveCheckBox.Location = New-Object System.Drawing.Size(50,35)
        $MoveCheckBox.Size = New-Object System.Drawing.Size(90,20)
        $MoveCheckBox.Checked=$False
        $MoveCheckBox.add_MouseHover($ShowHelp)
        $MoveCheckBox.Text = "Move"

        #Check box for xf switch 
        $xfCheckBox = New-Object System.Windows.Forms.checkbox
        $xfCheckBox.Name = "xfCheckBox"
        $xfCheckBox.Location = New-Object System.Drawing.Size(5,55)
        $xfCheckBox.Size = New-Object System.Drawing.Size(40,20)
        $xfCheckBox.Checked=$False
        $xfCheckBox.add_MouseHover($ShowHelp)
        $xfCheckBox.Text = "/xf:"
        $xfCheckBox.Add_CheckStateChanged({IF($xfCheckBox.Checkstate -eq "Checked") {$xfbox.Enabled = $true} IF($xfCheckBox.Checkstate -eq "unchecked") {$xfbox.Enabled = $false}})
        
        #Imput box for the xf switch options
        $xfbox = New-Object System.Windows.Forms.textBox 
        $xfbox.Location = New-Object System.Drawing.Size(45,55) 
        $xfbox.Size = New-Object System.Drawing.Size(85,20)
        $xfbox.Enabled = $False
        $xfbox.Font = "Courier New"

        #group box for the copy options
        $OptionsGroupBox = New-Object System.Windows.Forms.GroupBox
        $OptionsGroupBox.Location = New-Object System.Drawing.Size(375,5) 
        $OptionsGroupBox.size = New-Object System.Drawing.Size(190,80) 
        $OptionsGroupBox.text = "Options" 
        
        #Adds items to the form 
        $Form.Controls.Add($DonateButton)
        $Form.Controls.Add($outputBox)
        $Form.Controls.Add($HelpButton)
        $Form.Controls.Add($SourceBox)
        $Form.Controls.Add($DestinationBox)
        $Form.Controls.Add($DestinationBoxLabel)
        $Form.Controls.Add($SourceBoxLabel)
        $Form.Controls.Add($CopyButton)
        $Form.Controls.Add($StopButton)
        $Form.Controls.Add($BrowseSourceButton)
        $Form.Controls.Add($BrowseDestinationButton)
        $Form.Controls.Add($OptionsGroupBox)

        #Adds items to the copy options group box
        $OptionsGroupBox.Controls.Add($checkboxLog)
        $OptionsGroupBox.Controls.Add($FSOnlyCheckBox)
        $OptionsGroupBox.Controls.Add($ScheckBox)
        $OptionsGroupBox.Controls.Add($MoveCheckBox)
        $OptionsGroupBox.Controls.Add($xfCheckBox)
        $OptionsGroupBox.Controls.Add($xfbox)

        #shows the form
        $Form.Add_Shown({$Form.Activate()})
        [void] $Form.ShowDialog()
    }

    #Action for donate button
    Function Click_Donate
    {
        [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")
    }
    #action for help button
    Function Click_Help
    {
        $outputBox.Clear()
        $outputBox.AppendText("CopyTool - V 3.0.0.0`n")
        $outputBox.AppendText("Created By: Kris Gross`n")
        $outputBox.AppendText("Email: Krisgross@sccmtst.com`n")
        $outputBox.AppendText("Twitter: @kmgamd`n")
        $outputBox.AppendText("Updates can be found at: http://www.sccmtst.com/p/tool-downloads.html`n")
        $outputBox.AppendText("This version of CopyTool uses robocopy to copy files and folders.`n")
        $outputBox.AppendText("How To Use:`n")
        $outputBox.AppendText("`n")
        $outputBox.AppendText("1. Browse to or type the path to the content you want to copy or move`n")
        $outputBox.AppendText("`n")
        $outputBox.AppendText("2. Browse to or type the path to where you want the content to be copied or moved to`n")
        $outputBox.AppendText("`n")
        $outputBox.AppendText("3. Choose the options that meet your needs. Hover your mouse over the option for a desctiption of what it dose`n")
        $outputBox.AppendText("`n")
        $outputBox.AppendText("4. Click Start to start the copy process`n")
    }
    #action for Browse for Source 
    Function Click_BrowseSource
    {
        [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
        $SourceForm = New-Object System.Windows.Forms.FolderBrowserDialog
        $SourceForm.Rootfolder = "Desktop"
        $SourceForm.Description = "Select Folder"
        [void]$SourceForm.ShowDialog()
        $SourceForm.SelectedPath
        $Form.Dispose()
        $Form.Close()
        $Source = $SourceForm.SelectedPath
        Generate-Form
    }
    #action for Browse for destination
    Function Click_BrowseDestination
    {
        [CmdletBinding()]
        param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
        [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
        $destinationForm = New-Object System.Windows.Forms.FolderBrowserDialog
        $destinationForm.Rootfolder = $RootFolder
        $destinationForm.Description = $Description
        [void]$destinationForm.ShowDialog()
        $destinationForm.SelectedPath
        $Form.Dispose()
        $Form.Close()
        $Destination = $DestinationForm.SelectedPath
        Generate-Form
    }
    #action for the stop button
    function Click_Stop
    {
            Stop-Process -Name robocopy -Force
    }
    #actions for copy button
    Function Click_Copy
    {   
        #Sets the filter text to null so the same filter dosnt get used on a second copy job
        $FilterFiles = $null
        #if the log check box is checked create a log file
        if ($checkboxLog.Checked) {$switchLog = "/Log:$PSScriptRoot\copy.log"}
        #if FSonly check box sets needs swtches to copy only the file structure 
        if ($FSOnlyCheckBox.Checked) 
        {
            $FilterFiles = "*"
            $switchMIR = "/MIR" 
            $switchXF = "/xf"
        }
        #if move check box checked sets switches needs to move all files and folders
        if ($MoveCheckBox.Checked) 
        {
            $switchMOVE = "/MOVE"
            $switchE = "/E"
        } 
        #if the s check box checked sets the switch needs 
        If ($SCheckBox.Checked) {$switchS = "/S"}
        #if the xf check box is checked sets the xf switch and reads the filter fromt he xfbox
        IF ($xfCheckBox.Checked) 
        {
            $switchXF = "/xf"
            $FilterFiles = $xfbox.text
        }

        #Clears the outputbo so its easy to read after each copy job
        $outputBox.Clear()
        #sets the source for the Source box
        $Source = $SourceBox.Text
        #sets the Destination for the Destination box
        $Destination = $DestinationBox.text
        #runs teh copy process with the options you selected  
        Robocopy.exe $Source $Destination /J /R:0 /W:0 $switchLog $switchMIR $switchXF $FilterFiles $switchE $switchS $switchMOVE /TEE | foreach-Object {
            $ErrorActionPreference = "silentlycontinue"
            $outputBox.AppendText($_ + "`r`n")
            [void] [System.Windows.Forms.Application]::DoEvents()
        }
        if ($checkboxLog.Checked) {$outputBox.AppendText("Your log file can be found at $PSScriptRoot\Copy.log`n")}
    }

    Generate-Form 
}

#Burn a ISO to a USB
Function ISOtoUSB
{
        <#

    .SYNOPSIS
    Script to create a bootable flashdrive from a ISO

    .DESCRIPTION
    The script will launch a GUI. From the interafece you will be shown all of the drive on your computer
    first you 

    .NOTES
    Created By: Kris Gross
    Contact: KrisGross@sccmtst.com
    Twitter: @kmgamd


    .LINK
    http://sccmtst.com

    #>

    #Gets the volume info
    Function Get-Vol {
    Get-Volume | Select-Object -Property DriveLetter, FileSystem, Drivetype |
    Where-Object {$_.DriveLetter -ne $Null}
    }

    #Runs the Burn process
    Function Run-BurnISO 
    {

    #Sets ISO file and disk letter
    $iso = $textbox1.Text
    $disk = $textBox3.Text
    #Gets the disk number for diskpart
    $DriveNumber = (Get-Partition -DriveLetter $disk).DiskNumber
    #Mounts the ISO file
    Mount-DiskImage -ImagePath "$iso"
    # Get-Disk $DriveNumber | Clear-Disk -RemoveData
    Format-Volume -DriveLetter $disk -FileSystem FAT32 -NewFileSystemLabel USB

    #gets the drive letter of where the ISO gets mounted to
    $MountLetter = (Get-DiskImage $iso | Get-Volume).DriveLetter

    #Sets Variable for copy process
    $Source = $MountLetter + ":\"
    $Destination = $disk + ":\"
    $bootdir = $disk + ":"

    #Makes the drive bootbale
    bootsect.exe /nt60 $bootdir

    $Source=$Source.tolower()
    $Filelist = Get-Childitem $Source -Recurse
    $Total = $Filelist.count
    $Position = 0
    foreach ($File in $Filelist){
        $Filename=$File.Fullname.tolower().replace($Source,'')
        $DestinationFile=($Destination+$Filename)
        $Label4.text = "Burning $File"
        Copy-Item $File.FullName $DestinationFile -Force
        $Position++
        $Percentage = (($Position/$Total)*100)
        $PB.Value = $Percentage
        Start-Sleep -Milliseconds 150
     }

    #Dismounts the ISO file
    Dismount-DiskImage -ImagePath "$iso"

    [System.Windows.Forms.MessageBox]::Show("Your USB Drive is ready to use.")
    }

    #Opend the file broswser to select your ISO File
    Function Get-FilePath{
    [CmdletBinding()]
    Param(
        [String]$Filter = "|*.ISO",
        [String]$InitialDirectory = "C:\")

        [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $OpenFileDialog.initialDirectory = $InitialDirectory
        $OpenFileDialog.filter = $Filter
        [void]$OpenFileDialog.ShowDialog()
        $OpenFileDialog.filename
        #Runs the form function over so the results are added to the text box
        $Form.Close()
        $Form.Dispose()
        Generate-Form
    }

    Function Click_Donate
    {
        [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")
    }

    #Generates the form
    Function Generate-Form {

    #Needed for the form to show
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing

    #Set the standrads of the form window
    $form = New-Object System.Windows.Forms.Form 
    $form.Text = "ISOtoUSB - V 2.0.0.1"
    $form.Size = New-Object System.Drawing.Size(460,380) 
    $form.StartPosition = "CenterScreen"
    $Form.SizeGripStyle = "Hide"

    #sets the ok button
    $BurnButton = New-Object System.Windows.Forms.Button
    $BurnButton.Location = New-Object System.Drawing.Point(25,250)
    $BurnButton.Size = New-Object System.Drawing.Size(75,23)
    $BurnButton.Text = "Burn"
    $BurnButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $form.AcceptButton = $BurnButton
    $BurnButton.Add_Click({Run-BurnISO})

    #sets the cancel Button
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(125,250)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $form.CancelButton = $CancelButton

    #sets the Browse Button
    $BrowseButton = New-Object System.Windows.Forms.Button
    $BrowseButton.Location = New-Object System.Drawing.Point(320,160)
    $BrowseButton.Size = New-Object System.Drawing.Size(75,23)
    $BrowseButton.Text = "Browse"
    $BrowseButton.DialogResult = [System.Windows.Forms.DialogResult]::Yes
    $form.AcceptButton = $BrowseButton
    $BrowseButton.Add_Click({$textBox1.Text = Get-FilePath -InitialDirectory "$env:UserProfile\Desktop"})

    #sets the donate button
    $DonateButton = New-Object System.Windows.Forms.Button
    $DonateButton.Location = New-Object System.Drawing.Point(370,1)
    $DonateButton.Size = New-Object System.Drawing.Size(75,20)
    $DonateButton.Text = "Donate"
    $DonateButton.Add_Click({Click_Donate})

    #Text box for ISO file location
    $textBox1 = New-Object System.Windows.Forms.TextBox 
    $textBox1.Location = New-Object System.Drawing.Point(24,165)
    $textBox1.Size = New-Object System.Drawing.Size(260,22)
    $textBox1.Font = 'Lucida Console' 
    $textBox1.Text = $OpenFileDialog.filename

    #Sets the avalibale drives
    $textBox2 = New-Object System.Windows.Forms.TextBox
    $textBox2.Location = New-Object System.Drawing.Point(24,40) 
    $textBox2.Size = New-Object System.Drawing.Size(400,100)
    $textBox2.ReadOnly = $True
    $textBox2.Multiline = $True
    $textBox2.Font = 'Lucida Console'
    $textBox2.Text = Get-Vol | Format-Table | Out-String

    #Sets the entry box for Drive letter
    $textBox3 = New-Object System.Windows.Forms.TextBox
    $textBox3.Location = New-Object System.Drawing.Point(24,210)
    $textBox3.Size = New-Object System.Drawing.Size(260,22)
    $textBox3.Font = 'Lucida Console'
    $textBox3.Text = "Type the drive letter only"

    #Create a ProgressBar 
    $PB = New-Object System.Windows.Forms.ProgressBar
    $PB.Name = "PowerShellProgressBar"
    $PB.Size = New-Object System.Drawing.Size(400,20)
    $PB.Location = New-Object System.Drawing.Point(25,300)
    $PB.Value = 0
    $PB.Style="Continuous"

    #Label for Drive letter selcetion
    $label1 = New-Object System.Windows.Forms.Label
    $label1.Location = New-Object System.Drawing.Point(24,190)
    $label1.Size = New-Object System.Drawing.Size(280,13) 
    $label1.Text = "2. Drive:"

    #label for ISO path text box
    $label2 = New-Object System.Windows.Forms.Label
    $label2.Location = New-Object System.Drawing.Point(24,145)
    $label2.Size = New-Object System.Drawing.Size(280,13) 
    $label2.Text = "1. ISO File:"

    #lable for avaliable drives
    $label3 = New-Object System.Windows.Forms.Label
    $label3.Location = New-Object System.Drawing.Point(24,20) 
    $label3.Size = New-Object System.Drawing.Size(280,13) 
    $label3.Text = "Avaliable Drives:"

    $Label4 = New-Object System.Windows.Forms.Label
    $Label4.Location = New-Object System.Drawing.Point(25,280)
    $Label4.Size = New-Object System.Drawing.Size(280,13)
    $Label4.Text = ""

    #add all resorces of the form 
    $form.Controls.Add($BurnButton)
    $form.Controls.Add($CancelButton)
    $form.Controls.Add($BrowseButton)
    $form.Controls.Add($objDrives)
    $form.Controls.Add($textBox1)
    $form.Controls.Add($label1) 
    $form.Controls.Add($label2) 
    $form.Controls.Add($textBox2)
    $form.Controls.Add($textBox3)
    $form.Controls.Add($label3)
    $form.Controls.Add($label4)
    $form.Controls.Add($PB)
    $form.Controls.Add($DonateButton)

    #Show the Form 
    $form.Topmost = $True
    [void]$form.ShowDialog()
    }

    #Call the Function 
    Generate-Form
    

}

#Decompress Zip and Cab files
Function Decompress
{
    <#
    .SYNOPSIS
    This script is used to extract a cab or zip file 

    .DESCRIPTION
    The Script will launch a GUI that will allow you to browse for a zip or cab file. Then select a folder to extract to.
    You can also lauch the script with out a GUI by using the File and DecompressTo parameters.

    .PARAMETER File
    Specifyies the zip or cab file

    .PARAMETER DecompressTo
    Specifyies the location where the zip or cab should be decompressed to, if you do not specify this paramiter C:\Extracted_Files 
    will be used by default

    .EXAMPLE
    Extract.ps1 -File C:\Example.cab
    This will extract the cab file to C:\Exreacted_files and will not show the GUI

    .EXAMPLE
    Extract.ps1 -File C:\Example.zip -DecompressTo C:\Example
    Extracts the zip file to C:\Example and will not show the GUI

    .NOTES
    Created By: Kris Gross
    Contact: Krisgross@sccmtst.com
    Twitter: @kmgamd
    Version: 1.0.0.3

    .LINK
    http://www.sccmtst.com/
    #>


    Param(
        $File,
        $DecompressTo = "C:\Extracted_Files"
        )

    #Generates the form
    Function Generate-Form {

    #Needed for the form to show
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
    Add-Type -AssemblyName system.io.compression.filesystem
    #Set the standrads of the form window
    $form = New-Object System.Windows.Forms.Form 
    $form.Text = "Decompresstion Tool - V 1.0.0.3"
    $form.Size = New-Object System.Drawing.Size(460,280) 
    $form.StartPosition = "CenterScreen"
    $form.TopMost = $True
    $Form.SizeGripStyle = "Hide"

    #sets the ok button
    $ExtractButton = New-Object System.Windows.Forms.Button
    $ExtractButton.Location = New-Object System.Drawing.Point(50,180)
    $ExtractButton.Size = New-Object System.Drawing.Size(300,23)
    $ExtractButton.Text = "Decompress"
    $ExtractButton.Add_Click({Click_Extract})

    #sets the Browse Button for the File
    $FindFileButton = New-Object System.Windows.Forms.Button
    $FindFileButton.Location = New-Object System.Drawing.Point(320,70)
    $FindFileButton.Size = New-Object System.Drawing.Size(75,23)
    $FindFileButton.Text = "Browse"
    $FindFileButton.Add_Click({Get-FilePath})

    #sets the Browse Button for the Folder
    $FindFolderButton = New-Object System.Windows.Forms.Button
    $FindFolderButton.Location = New-Object System.Drawing.Point(320,140)
    $FindFolderButton.Size = New-Object System.Drawing.Size(75,23)
    $FindFolderButton.Text = "Browse"
    $FindFolderButton.Add_Click({Get-FolderPath})

    #sets the donate button
    $DonateButton = New-Object System.Windows.Forms.Button
    $DonateButton.Location = New-Object System.Drawing.Point(370,1)
    $DonateButton.Size = New-Object System.Drawing.Size(75,20)
    $DonateButton.Text = "Donate"
    $DonateButton.Add_Click({Click_Donate})

    #Sets the box showing the File selected
    $FileBox = New-Object System.Windows.Forms.TextBox 
    $FileBox.Location = New-Object System.Drawing.Point(24,80)
    $FileBox.Size = New-Object System.Drawing.Size(260,22)
    $FileBox.Font = 'Lucida Console' 
    $FileBox.Text = $FileText

    #Sets the box showing the selected folder
    $FolderBox = New-Object System.Windows.Forms.TextBox
    $FolderBox.Location = New-Object System.Drawing.Point(24,140)
    $FolderBox.Size = New-Object System.Drawing.Size(260,22)
    $FolderBox.Font = 'Lucida Console'
    $FolderBox.Text = $FolderText

    #label for file box
    $FileBoxLabel = New-Object System.Windows.Forms.Label
    $FileBoxLabel.Location = New-Object System.Drawing.Point(24,60)
    $FileBoxLabel.Size = New-Object System.Drawing.Size(280,13) 
    $FileBoxLabel.Text = "1. File:"

    #Label for folder box
    $ExtractLabel = New-Object System.Windows.Forms.Label
    $ExtractLabel.Location = New-Object System.Drawing.Point(24,120)
    $ExtractLabel.Size = New-Object System.Drawing.Size(280,13) 
    $ExtractLabel.Text = "2. Decompress To:"

    #Label for the form
    $FormLabel = New-Object System.Windows.Forms.Label
    $FormLabel.Location = New-Object System.Drawing.Point(24,20)
    $FormLabel.Size = New-Object System.Drawing.Size(280,13)
    $FormLabel.Text = "Use this tool to decompress a ZIP or CAB file"

    #tells the progress of the extraction process
    $RunningLabel = New-Object System.Windows.Forms.Label
    $RunningLabel.Location = New-Object System.Drawing.Point(24,215)
    $RunningLabel.Size = New-Object System.Drawing.Size(280,13)
    $RunningLabel.ForeColor = "Red"
    $RunningLabel.Text = "Decompressing files"
    $RunningLabel.Visible = $false

    #add all resorces of the form 
    $form.Controls.Add($ExtractButton)
    $form.Controls.Add($FindFileButton)
    $form.Controls.Add($FindFolderButton)
    $form.Controls.Add($FileBox)
    $form.Controls.Add($ExtractLabel) 
    $form.Controls.Add($FileBoxLabel) 
    $form.Controls.Add($FolderBox)
    $form.Controls.Add($FormLabel)
    $form.Controls.Add($RunningLabel)
    $form.Controls.Add($DonateButton)

    #Show the Form
    [void]$form.ShowDialog() 
    }

    #action taken then extract is pressed
    function Click_Extract
    {
        $File = $FileBox.Text
        $DecompressTo = $FolderBox.Text
        #Gets the file extention for the selected file
        $Extention = [System.IO.Path]::GetExtension("$File")
        #performs action based on file extention
        if ($Extention -eq ".cab") 
        {
            $RunningLabel.Visible = $true
            expand $File -f:* $DecompressTo
        }
        if ($Extention -eq ".zip")
        {
            $RunningLabel.Visible = $true
            [io.compression.zipfile]::ExtractToDirectory($file, $DecompressTo)
        }
        $RunningLabel.Text ="Completed"
        $RunningLabel.ForeColor = "Green"
        $FolderBox.Text = ""
        $FileBox.Text = ""
    }

    #form used to select the file
    Function Get-FolderPath
    {
        [CmdletBinding()]
        param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
        [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
        $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
        $objForm.Rootfolder = $RootFolder
        $objForm.Description = $Description
        [void]$objForm.ShowDialog()
        $objForm.SelectedPath
        $FolderText = $objForm.SelectedPath
        $Form.Close()
        $Form.Dispose()
        Generate-Form
    }

    #form used to select the folder
    Function Get-FilePath 
    {
        [CmdletBinding()]
        Param(
        [String]$Filter = "|*.*",
        [String]$InitialDirectory = "C:\")
        [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $OpenFileDialog.initialDirectory = $InitialDirectory
        $OpenFileDialog.filter = $Filter
        [void]$OpenFileDialog.ShowDialog()
        $OpenFileDialog.filename
        #Runs the form function over so the results are added to the text box
        $FileText = $OpenFileDialog.filename
        $Form.Close()
        $Form.Dispose()
        Generate-Form
    }

    Function Click_Donate
    {
        [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")
        (New-Object -Com Shell.Application).Open("https://www.paypal.me/jackofalltech")
    }

    #action taken when the GUI is not used
    function extract
    {   
        #Crates the Extract to folder if it dose not exist
        if (($DecompressTo)){mkdir $DecompressTo}
        #gets the slected file extention
        $Extention = [System.IO.Path]::GetExtension("$File")
        #preforms a action based on selected file extention
        if ($Extention -eq ".cab") 
        {
            expand $File -f:* $DecompressTo
        }
        if ($Extention -eq ".zip")
        {
            [io.compression.zipfile]::ExtractToDirectory($file, $DecompressTo)
        }
    }

    #Call the Function based on paramiters
    if (($Cab)){Extract} else {Generate-Form}
}

Function Get-ADUserAccount
{
    <#
    .SYNOPSIS
    Gets Info about the specified user account 

    .DESCRIPTION
    Displays the Display Name, Sam Account Name, SID, Canonical Name, mail, Initials, Date Created, Last Logon Date, 
    Password Exired state, When the password was last set, If the password exires, if a password is required, if the account is locked out, bad password count 

    .PARAMETER User
    Specifies the user to look up 
    
    .NOTES
    Created By: Kris Gross
    Contact: Krisgross@sccmtst.com
    Twitter: @kmgamd
    Version: 1.0.0.0

    .LINK
    http://www.sccmtst.com/
    #>
     Param(
        [Parameter(Mandatory=$True)]
        $User
        )
    Get-AdUser -Identity $user -Properties * | Format-list DisplayName, SamAccountName, SID, CanonicalName, mail, Initials, Created, LastLogonDate, PasswordExired, PasswordLastSet, PasswordNeverExpires, PasswordNotRequired, LockedOut, badPwdCount
}

Function Reset-UserPassword
{
    Param(
        [Parameter(Mandatory=$True)]
        $User
    )
    Set-ADAccountPassword -Identity $User -Reset
    Set-ADUser -Identity $User -ChangePasswordAtLogon $True
}

Function Change-UserPassword
{
    Param(
        [Parameter(Mandatory=$True)]
        $User
    )
    Set-ADAccountPassword -Identity $User -Reset
}

Clear-Host
Write-Host "User: $ENV:USERNAME"
Write-Host "Domain: $ENV:USERDOMAIN"
Write-Host "Computer Name: $ENV:COMPUTERNAME"
Write-Host "Execution Policy: $ExecutionPolicy"
Write-Host 

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

Windows 10 Setup Script - Version 2.5.0.1