4
\$\begingroup\$

I wrote a PS script to backup data from single user pcs to their network homedrive. The purpose of this tool is to save some time and ensure process consistency when reimaging/replacing machines. I would appreciate your critiques and ideas. I am new to Powershell scripting.

Breakdown of the scripts job:

BACKUP:

  1. Creates a folder on the user's Home drive named Desktop Backup.
  2. Creates a subfolder within the Desktop Backup folder called %WorkstationName%.%date% (IE: H:\Desktop Backup\WC3ISYW257.1.21.2015).
  3. Copies all the Office Documents and Data files from the workstation C drive to the %WorkstationName%.%date% folder. The file types include:(".pptx",".xlsx",".accdb",".docx",".pst",".xls",".doc",".pab",".pdf",".ppt",".mdb",".jpg",".bmp",".gif",".vsd",".mp*",".doc",".xltx",".xltm",".xlam",".ppt*",".potx",".potm",".ppam",".ppsx",".ppsm",".acc*",".pdf",".jpeg",".png",".csv")
  4. Creates a subfolder within the %WorkstationName%.%Date% folder called Configuration(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Configuration).
  5. Creates seperate text files within the Configuration folder containing information on user's mapped drives, remote desktop users on the machine, administrator accounts on the machine, and mapped printers.
  6. Creates a subfolder within the %WorkstationName%.%Date% folder called Desktop(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Desktop).
  7. Copies all the user's Desktop folder to the Desktop folder, excluding *lnk, *.url, and *.exe files.
  8. Creates a subfolder within the %WorkstationName%.%Date% folder called Office Files(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files).
  9. Creates a subfolder within the Office Files folder called NK2(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\NK2).
  10. Copies all the files from the user's Outlook folder to the NK2 folder.
  11. Creates a subfolder within the Office Files folder called Proof(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\Proof).
  12. Copies all the files from the user's Proof folder to the Proof folder.
  13. Creates a subfolder within the Office Files folder called Signatures(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\Signatures).
  14. Copies all the files from the user's Signatures folder to the Signatures folder.
  15. Creates a subfolder within the Office Files folder called Quick Launch(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\Quick Launch).
  16. Copies all the files from the user's Quick Launch folder to the Quick Launch folder.

RESTORE:

  1. Copies all the files from the users NK2 folder (IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\NK2) to the user's Outlook folder.
  2. Copies all the files from the Proof folder (IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\Proof) to the user's Proof folder.
  3. Copies all the files from the Signatures folder(IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Office Files\Signatures) to the user's Signatures folder.
  4. Copies all the files from the users Desktop folder (IE: H:\Desktop Backup\WC3ISYW257.1.21.2015\Desktop) to the user's desktop (excluding *.lnk, *.url, and *.exe). The Restore function does not put the users HomeDrive data back on the C:\ as we are trying to encourage users to not use the C:\ for storage. It also does not restore the quick launch bar. It also excludes the restore of *.lnk, *.url, and *.exe from the user's desktop. The reason for these is backwards/forwards Windows XP/7 OS compatibility.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Management")

#Generated Form Function
function GenerateForm {
########################################################################
# Created On: 1/19/2015
# Generated By: Josh Pratt
########################################################################

$date = Get-Date -Format "d.M.yyyy_h_m_s"

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$formDSBACKUP = New-Object System.Windows.Forms.Form
$label1 = New-Object System.Windows.Forms.Label
$RESTORE = New-Object System.Windows.Forms.Button
$BACKUP = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects



$BACKUP_OnClick= 
{


    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    #endregion

    #region Generated Form Objects
    $formBACKUP = New-Object System.Windows.Forms.Form
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $label1 = New-Object System.Windows.Forms.Label
    $BACKUPall = New-Object System.Windows.Forms.Button
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    $computername = $env:COMPUTERNAME
    $date = Get-Date -Format "M.d.yyyy"
    #endregion Generated Form Objects

        $BACKUPall_OnClick= 
        {
            #region Generated Form Objects
    $formBACKUP = New-Object System.Windows.Forms.Form
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $label1 = New-Object System.Windows.Forms.Label
    $BACKUPall = New-Object System.Windows.Forms.Button
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    $date = Get-Date -Format "M.d.yyyy"
    $Include = @("*.pptx","*.xlsx","*.accdb","*.docx","*.pst","*.xls","*.doc","*.pab","*.pdf","*.ppt","*.mdb","*.jpg","*.bmp","*.gif","*.vsd","*.mp*","*.doc*","*.xltx","*.xltm","*.xlam","*.ppt*","*.potx","*.potm","*.ppam","*.ppsx","*.ppsm","*.acc*","*.pdf*","*.jpeg*","*.png*","*.csv*") 
    $this = $env:username
    $this2 = $env:username
    $Desktop = [Environment]::GetFolderPath("Desktop")
    $exclude = @('*.lnk','*.url','*.exe')
    $dest = "H:\Desktop Backup\$computername.$date\Desktop"
    #endregion Generated Form Objects

        $Result = Test-Path -Path "C:\Program Files (x86)"
            if($Result -eq $true){
                New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\configuration"
    				Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName >> "H:\Desktop Backup\$computername.$date\configuration\MappedDrives.txt"
                Get-WmiObject -class Win32_printer | ft name, systemName, shareName >> "H:\Desktop Backup\$computername.$date\configuration\printers.txt"
    				net localgroup "Remote Desktop Users" >> "H:\Desktop Backup\$computername.$date\configuration\RemoteDesktopUsers.txt"
                net localgroup Administrators >> "H:\Desktop Backup\$computername.$date\configuration\Administrators.txt"
    				Get-ChildItem c:\ -Include $include -Recurse | where {$_ -notmatch 'Windows'}| where{$_ -notmatch 'Program Files'} | where {$_ -notmatch 'inetpub'} | where {$_ -notmatch 'Desktop'}|Foreach{Copy-Item $_.fullname "H:\Desktop Backup\$computername.$date"}
    				New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Quick Launch"
                Get-ChildItem "C:\Users\$this\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch" | % {
    					Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Quick Launch" -Recurse  -Force
                        }

                New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Signatures"
    				Get-ChildItem "C:\Users\$this\AppData\Roaming\Microsoft\Signatures" | % {
                    Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Signatures" -Recurse  -Force
                        }

                New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Proof"
    				Get-ChildItem "C:\Users\$this\AppData\Roaming\Microsoft\Proof" | % {
                    Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Proof" -Recurse  -Force
                        }

                New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\NK2"
    				Get-ChildItem "C:\Users\$this\AppData\Roaming\Microsoft\Outlook" | % {
                    Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\NK2" -Recurse  -Force
                        } 

                    New-Item -ItemType Directory -Path $dest
                    Get-ChildItem $Desktop -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($Desktop.length)}| out-null
                } 
            else {
                New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\configuration"
    				Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName >> "H:\Desktop Backup\$computername.$date\configuration\MappedDrives.txt"
                Get-WmiObject -class Win32_printer | ft name, systemName, shareName >> "H:\Desktop Backup\$computername.$date\configuration\printers.txt"
    				net localgroup "Remote Desktop Documents and Settings" >> "H:\Desktop Backup\$computername.$date\configuration\RemoteDesktopUsers.txt"
                net localgroup Administrators >> "H:\Desktop Backup\$computername.$date\configuration\Administrators.txt"
    				Get-ChildItem c:\ -Include $include -Recurse | where {$_ -notmatch 'Windows'}| where{$_ -notmatch 'Program Files'} | where {$_ -notmatch 'inetpub'} | where {$_ -notmatch 'Desktop'}|Foreach{Copy-Item $_.fullname "H:\Desktop Backup\$computername.$date"}
    				New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Quick Launch"
                Get-ChildItem "C:\Documents and Settings\$this2\Application Data\Microsoft\Internet Explorer\Quick Launch" | % {
    					Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Quick Launch" -Recurse  -Force
    					}
    				New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Signatures"
                Get-ChildItem "C:\Documents and Settings\$this2\Application Data\Microsoft\Signatures" | % {
    					Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Signatures" -Recurse  -Force
    					}
    				New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\Proof"
                Get-ChildItem "C:\Documents and Settings\$this2\Application Data\Microsoft\Proof" | % {
    					Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\Proof" -Recurse  -Force
    					}
    				New-Item -ItemType Directory -Path "H:\Desktop Backup\$computername.$date\Office Files\NK2"
                Get-ChildItem "C:\Documents and Settings\$this2\Application Data\Microsoft\Outlook" | % {
    					Copy-Item $_.FullName "H:\Desktop Backup\$computername.$date\Office Files\NK2" -Recurse -Force
                    } 
                New-Item -ItemType Directory -Path $dest
                Get-ChildItem $Desktop -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($Desktop.length)}| out-null
                } 
        $outputBox.text = "BACKUP COMPLETE"
        Start-Sleep -S 10
        $formBACKUP.close()
        }


    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
        $formBACKUP.WindowState = $InitialFormWindowState
    }

    #----------------------------------------------
    #region Generated Form Code
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 240
    $System_Drawing_Size.Width = 450
    $formBACKUP.ClientSize = $System_Drawing_Size
    $formBACKUP.DataBindings.DefaultDataSourceUpdateMode = 0
    $formBACKUP.Name = "formBACKUP"
    $formBACKUP.Text = "BACKUP"
    $formBACKUP.StartPosition = "CenterScreen"
    $outputBox = New-Object System.Windows.Forms.TextBox
    $outputBox.Location = New-Object System.Drawing.Size(25, 187)
    $outputBox.Size = New-Object System.Drawing.Size(400, 50)
    $outputBox.MultiLine = $True

    $formBACKUP.Controls.Add($outputBox)


    $outputbox.DataBindings.DefaultDataSourceUpdateMode = 0



    $BACKUPall.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 25
    $System_Drawing_Point.Y = 160
    $BACKUPall.Location = $System_Drawing_Point
    $BACKUPall.Name = "BACKUPall"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 400
    $BACKUPall.Size = $System_Drawing_Size
    $BACKUPall.TabIndex = 2
    $BACKUPall.Text = "BACKUP"
    $BACKUPall.UseVisualStyleBackColor = $True
    $BACKUPall.add_Click($BACKUPall_OnClick)

    $formBACKUP.Controls.Add($BACKUPall)

    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Location = New-Object System.Drawing.Size(25, 6)
    $Label1.size = New-Object System.Drawing.Size(400, 800)
    $Label1.text = "Pressing Backup will:

    1. Create a folder called Desktop Backup on the H drive. 
    2. Create text files to record rights, mapped drives, and printers.
    3. Backup all data files and office documents.
    4. Backup custom features such as NK2, signature,dictionary, and quick launch files.

    Once pressed this tool will appear to freeze. Leave it alone until you see BACKUP COMPLETE below."
    $Font = New-Object System.Drawing.Font("Times New Roman",9.75,[System.Drawing.FontStyle]::bold)
    # Font styles are: Regular, Bold, Italic, Underline, Strikeout
    $label1.Font = $Font
    $formBACKUP.Controls.Add($Label1)

    #endregion Generated Form Code

    #Save the initial state of the form
    $InitialFormWindowState = $formBACKUP.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $formBACKUP.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $formBACKUP.ShowDialog()| Out-Null

}   
$RESTORE_OnClick= 
{

    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    #endregion

    #region Generated Form Objects
    $formrestore = New-Object System.Windows.Forms.Form
    $comboBox2 = New-Object System.Windows.Forms.ComboBox
    $label1 = New-Object System.Windows.Forms.Label
    $Restore2 = New-Object System.Windows.Forms.Button
    $user = [Environment]::UserName
    $Desktop2 = [Environment]::GetFolderPath("Desktop")
    $NK2 = "C:\users\$user\AppData\Roaming\Microsoft\Outlook"
    	$Signatures = "C:\users\$user\AppData\Roaming\Microsoft\Signatures"
    $NK2_XP = "C:\documents and Settings\$user\Application Data\Microsoft\Outlook"
    	$Signatures_XP = "C:\documents and Settings\$user\Application Data\Microsoft\Signatures"
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    $QL_XP = "C:\documents and Settings\$user\Application Data\Microsoft\Internet Explorer\Quick Launch"
    	$QL = "C:\users\$user\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch"
    $PROOF_XP = "C:\Documents and Settings\$user\Application Data\Microsoft\Proof"
    	$PROOF = "C:\users\$user\AppData\Roaming\Microsoft\Proof"
    $computername = $env:COMPUTERNAME

    #endregion Generated Form Objects

        $Restore2_OnClick= 
        {$SelectedItem = $comboBox2.SelectedItem.ToString()
        $Result = Test-Path -Path "C:\Program Files (x86)"
            if($Result -eq $true){
                Get-ChildItem "H:\Desktop Backup\$SelectedItem\Desktop" | % {
    				Copy-Item $_.FullName -Destination $Desktop2 -Recurse 
    				}
    				New-Item -ItemType Directory -Path $Signatures
    				Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\Signatures" | % {
                Copy-Item $_.FullName -Destination $Signatures -Recurse 
                }
                New-Item -ItemType Directory -Path $NK2
                Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\NK2" | % {
    				Copy-Item $_.FullName -Destination $NK2 -Recurse 
    				}
    				New-Item -ItemType Directory -Path $PROOF
    				Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\Proof" | % {
                Copy-Item $_.FullName -Destination $PROOF -Recurse 
                }}
            else {Get-ChildItem "H:\Desktop Backup\$SelectedItem\Desktop" | % {
    				Copy-Item $_.FullName -Destination $Desktop2 -Recurse 
    				}
    				New-Item -ItemType Directory -Path $Signatures_XP
    				Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\Signatures" | % {
                Copy-Item $_.FullName -Destination $Signatures_XP -Recurse 
                }
                New-Item -ItemType Directory -Path $NK2_XP
                Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\NK2" | % {
    				Copy-Item $_.FullName -Destination $NK2_XP -Recurse 
    				}
    				Get-ChildItem "H:\Desktop Backup\$SelectedItem\Office Files\Proof" | % {
                Copy-Item $_.FullName -Destination $PROOF_XP -Recurse 
                }}
                $formrestore.close()
        }


    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
        $formrestore.WindowState = $InitialFormWindowState
    }

    #----------------------------------------------
    #region Generated Form Code
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 240
    $System_Drawing_Size.Width = 450
    $formrestore.ClientSize = $System_Drawing_Size
    $formrestore.DataBindings.DefaultDataSourceUpdateMode = 0
    $formrestore.Name = "formrestore"
    $formrestore.Text = "RESTORE"
    $formrestore.StartPosition = "CenterScreen"
#   $outputBox = New-Object System.Windows.Forms.TextBox
#   $outputBox.Location = New-Object System.Drawing.Size(10, 60)
#   $outputBox.Size = New-Object System.Drawing.Size(430, 160)
#   $outputBox.MultiLine = $True
#   $outputBox.ScrollBars = "Vertical"
#
#   $formrestore.Controls.Add($outputBox)


    $outputbox.DataBindings.DefaultDataSourceUpdateMode = 0



    $Restore2.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 270
    $System_Drawing_Point.Y = 205
    $Restore2.Location = $System_Drawing_Point
    $Restore2.Name = "Restore"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 175
    $Restore2.Size = $System_Drawing_Size
    $Restore2.TabIndex = 2
    $Restore2.Text = "Restore"
    $Font = New-Object System.Drawing.Font("Times New Roman",9.75,[System.Drawing.FontStyle]::Bold)
    $Restore2.font = $Font 
    $Restore2.UseVisualStyleBackColor = $True
    $Restore2.add_Click($Restore2_OnClick)
    $comboBox2.DataBindings.DefaultDataSourceUpdateMode = 0
    $comboBox2.FormattingEnabled = $True
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 1
    $System_Drawing_Point.Y = 205
    $comboBox2.Location = $System_Drawing_Point
    $comboBox2.Name = "comboBox2"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 21
    $System_Drawing_Size.Width = 259
    $comboBox2.Size = $System_Drawing_Size
    $comboBox2.TabIndex = 4

$Result = Test-Path -Path "C:\Program Files (x86)"
            if($Result -eq $true){$win = Get-ChildItem "H:\Desktop Backup"
#       $ders = Where-Object {$win -like "Windows.*"}
        foreach($item in $win) {
            if($item.name -like "*.*"){
            $comboBox2.items.add($item.name)
            }}}
            else {$win = Get-ChildItem "H:\Desktop Backup"
#       $ders = Where-Object {$win -like "Windows.*"}
        foreach($item in $win) {
            if($item.name -like "Personal Settings.*"){
            $comboBox2.items.add($item.name)
            }}}


    $formrestore.Controls.Add($combobox2)
    $formrestore.Controls.Add($Restore2)



    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Location = New-Object System.Drawing.Size(1, 6)
    $Label1.size = New-Object System.Drawing.Size(400, 800)
    $Label1.text = "        Clicking restore will perform the following:
    1. Restore Desktop documents
    2. Restore NK2 files
    3. Restore Signature files
    4. Restore Proof files

    Select the Computer's Backup folder using the drop down box below.
    Once selected please click Restore.
    This window will close once items have been restored.

    Please note for NK2 and Signature files: 
    You will still have to select them from within Outlook."
    $Font = New-Object System.Drawing.Font("Times New Roman",9.75,[System.Drawing.FontStyle]::Bold)
    # Font styles are: Regular, Bold, Italic, Underline, Strikeout
    $label1.Font = $Font
    $formrestore.Controls.Add($Label1)

    #endregion Generated Form Code

    #Save the initial state of the form
    $InitialFormWindowState = $formrestore.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $formrestore.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $formrestore.ShowDialog()| Out-Null

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $formDSBACKUP.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 300
$System_Drawing_Size.Width = 284
$formDSBACKUP.ClientSize = $System_Drawing_Size
$formDSBACKUP.DataBindings.DefaultDataSourceUpdateMode = 0
$formDSBACKUP.Name = "formDSBACKUP"
$formDSBACKUP.Text = "SaveIT! - Desktop Backup Tool"
$formDSBACKUP.StartPosition = "WindowsDefaultLocation"
$formDSBACKUP.StartPosition = "CenterScreen"

$label1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 1
$Font = New-Object System.Drawing.Font("Times New Roman",9.75,[System.Drawing.FontStyle]::Bold)
# Font styles are: Regular, Bold, Italic, Underline, Strikeout
$label1.Font = $Font
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 225
$System_Drawing_Size.Width = 259
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 3
$label1.Text = "
Choose the function you are looking to perform:

BACKUP: If this is a machine that is being replaced/reimaged.

RESTORE: If this is a machine that has been replaced or reimaged.

PLEASE NOTE: The restore portion of this tool will only work if you used this tool to backup this users information previously"

$formDSBACKUP.Controls.Add($label1)

$RESTORE.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 20
$System_Drawing_Point.Y = 255
$RESTORE.Location = $System_Drawing_Point
$RESTORE.Name = "RESTORE"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 240
$RESTORE.Size = $System_Drawing_Size
$RESTORE.TabIndex = 1
$RESTORE.Text = "RESTORE"
$RESTORE.UseVisualStyleBackColor = $True
$RESTORE.add_Click($RESTORE_OnClick)

$formDSBACKUP.Controls.Add($RESTORE)

$BACKUP.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 20
$System_Drawing_Point.Y = 225
$BACKUP.Location = $System_Drawing_Point
$BACKUP.Name = "BACKUP"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 240
$BACKUP.Size = $System_Drawing_Size
$BACKUP.TabIndex = 1
$BACKUP.Text = "BACKUP"
$BACKUP.UseVisualStyleBackColor = $True
$BACKUP.add_Click($BACKUP_OnClick)

$formDSBACKUP.Controls.Add($BACKUP)


$formDSBACKUP.Controls.Add($PRTADTW705)


#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $formDSBACKUP.WindowState
#Init the OnLoad event to correct the initial state of the form
$formDSBACKUP.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$formDSBACKUP.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm
\$\endgroup\$
1
\$\begingroup\$

I'm not very good at powershell, but there are a few very important file extensions missing from your list.

  1. *.xlsm : Macro enabled Excel Workbooks
  2. *.xlsb : Binary Excel Workbooks (No. I don't understand why people use this file type, but trust me, they do.)
  3. *.txt : The trusty text file. I have a few of these of these around that I would be down right distraught over losing.

I would at least consider including all of Excel's supported file types. A complete list can be found here.

https://support.office.com/en-au/article/File-formats-that-are-supported-in-Excel-a28ae1d3-6d19-4180-9209-5a950d51b719

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.