Second part of
migration script that use report from previous post "Windows XP software script". Once we choose old
computer report program checked txt Windows XP report file with special csv
file (ProgramList.csv) that have old Windows XP program name, new Windows 7
program name same as installed program name*. After removed from main report
Windows 7 program, Windows updates, office updates, drivers, hotfix etc. and
created final list software (soft_list.txt) on %HOMEDRIVE%\Install folder what
we need more install on this pc. At the end requested copy install folder on
computer and started install it.
* - Installed folder have path: ---%hard_drive%\Install
Pkg\%name_program_folder_for_install%\Completed --- and have install.bat that
started installation program.
* - Format csv file data (sample):
1 column - Windows
XP old program name (7-Zip 9.20)
2 column - special
for manual install
3 column - name
program folder for install (IgorPavlov_7-Zip_9.20_x64)
4 column -
installed program on Windows 7 (7-Zip 9.20 (x64 edition))
function findinarr
($array,
$value,
$columnIn,
$columnOut) {
for ($n=0; $n -lt $array.count;
$n++)
{
if ($array[$n][$columnIn] -eq $value)
{ Return $array[$n][$columnOut] }
}
}
function findinobj
($array,
$value,
$columnIn,
$columnOut) {
for ($n=0; $n -lt $array.count;
$n++)
{
if ($array[$n].$columnIn -eq
$value) { Return
$array[$n].$columnOut }
}
}
function GetSoftware
($request) {
$hive="HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
if (Test-Path $hive){
$param
= Get-ChildItem
$hive
foreach
($p in
$param){
foreach
($key in
$p.getValue("DisplayName")){
if
($key -eq
$request) {Return
$request}
}
}
}
}
function CheckBat
()
{
$alert = $false
if ((Get-Item
"$programm_path\soft_list.txt").length
-gt 0kb)
{
$Copy_to_local = Read-Host "Do you want copy install folder to local
computer?"
if ($Copy_to_local
-eq "y")
{
cls
Write-Host "Check install.bat file in programm folders"
Write-Host "----------------------------------------"
$SoftFile
= new-object
System.IO.StreamReader($programm_path+"\soft_list.txt")
try
{
while
(($soft_line =
$SoftFile.ReadLine())
-ne $null)
{
if
($soft_line -ne
"")
{
$install_folder
= "$env:drive\Install
Pkg\$soft_line"
$bat_file
= "$install_folder\Completed\install.bat"
if
(Test-Path -path
$bat_file)
{
if
($soft_line -eq
"Oracle_Client10gR2_10.2.0.5.0_x86_v2")
{
if (Test-Path -path "$env:SystemDrive\Completed")
{ Write-Host $soft_line
"copied" }
else { Robocopy.exe "$install_folder\Completed" "$env:SystemDrive\Completed"
* /e
/eta }
}
Robocopy.exe
$install_folder $programm_path\$soft_line
* /e
/eta
if
(Test-Path -path
$programm_path\$soft_line) { Write-Host
$soft_line "copied"
-foregroundcolor "Green"
}
else
{ Write-Host $soft_line
"copying" }
}
else
{
Write-Host
$soft_line -foregroundcolor
"RED"
$alert
= $true
}
}
}
}
finally
{ $SoftFile.Close()
}
}
}
Return $alert
}
$ValueFromPipeline=$true
$ValueFromPipelineByPropertyName=$true
$ComputerName = $env:computername
$win7app1 = New-Object System.Collections.ArrayList
$UninstallRegKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
foreach($Computer
in $ComputerName)
{
Write-Output
"Computer: $Computer"
if(Test-Connection -ComputerName
$Computer -Count
1 -ea 0)
{
# Get the
architecture 32/64 bit
if
((Get-WmiObject -Class
Win32_OperatingSystem -ComputerName $Computer
-ea 0).OSArchitecture -eq
'64-bit')
{
#
If 64 bit check both 32 and 64 bit locations in the registry
$RegistryViews
= @('Registry32','Registry64')
} else
{
#
Otherwise only 32 bit
$RegistryViews
= @('Registry32')
}
foreach
( $RegistryView in
$RegistryViews )
{
#
Get the reg key(s) where add/remove program information is stored.
$HKLM = [microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computer,$RegistryView)
$UninstallRef
= $HKLM.OpenSubKey($UninstallRegKey)
$Applications
= $UninstallRef.GetSubKeyNames()
#
Now we have the registry locations, call the function which will enumerate
#
all the applications on this PC
foreach
($App in
$Applications)
{
$AppRegistryKey
= $UninstallRegKey
+ "\\"
+ $App
$AppDetails
= $HKLM.OpenSubKey($AppRegistryKey)
$AppGUID
= $App
$AppDisplayName
= $($AppDetails.GetValue("DisplayName"))
$AppVersion
= $($AppDetails.GetValue("DisplayVersion"))
$AppPublisher
= $($AppDetails.GetValue("Publisher"))
$AppInstalledDate
= $($AppDetails.GetValue("InstallDate"))
$AppUninstall
= $($AppDetails.GetValue("UninstallString"))
if(!$AppDisplayName)
{ continue }
$OutputObj
= New-Object
-TypeName PSobject
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name ComputerName
-Value $Computer.ToUpper()
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name Name
-Value $AppDisplayName
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name AppVersion
-Value $AppVersion
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name AppVendor
-Value $AppPublisher
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name InstalledDate
-Value $AppInstalledDate
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name UninstallKey
-Value $AppUninstall
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name AppGUID
-Value $AppGUID
if
($RegistryView -eq
'Registry32')
{
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name Arch
-Value '32'
} else
{
$OutputObj
| Add-Member
-MemberType NoteProperty
-Name Arch
-Value '64'
}
$win7app1.Add($OutputObj)
> $null
}
}
}
}
$programm_path = "$env:HOMEDRIVE\Install"
$item_to_del = "$programm_path\soft_list.txt"
if (!(Test-Path -path $programm_path)) { New-Item
-Path "$env:HOMEDRIVE\"
-ItemType directory
-Name Install
}
if (Test-Path
-path $item_to_del)
{ remove-item -path
$programm_path\soft_list.txt
-force }
new-item -path $programm_path -name
soft_list.txt -type
"file"
cls
$dr = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition).ToString()
$drive = $dr
$MainFile = new-object System.IO.StreamReader($drive+"\ProgramList.csv")
$ProgrammsForCompare = New-Object System.Collections.ArrayList
try {
while
(($line =
$MainFile.ReadLine())
-ne $null)
{ $ProgrammsForCompare.Add($line.Split(","))
> $null
}
}
finally { $MainFile.Close() }
$Backup_txt = get-childitem "$drive\Backup_list" |
ForEach-Object {$_
-Replace "software_list_", ""}| ForEach-Object
{$_ -Replace
".txt",
""}
for ($i
= 0; $i -ne $Backup_txt.Count;
$i++)
{ Write-Host $i
"-"$Backup_txt[$i] }
do
{
$Customer
= Read-Host
"Choose customer name"
cls
Write-Host "Report for"$Backup_txt[$Customer]
Write-Host "----------------------------------------"
$PathForXPList
= $drive+"\Backup_list\software_list_"+$Backup_txt[$Customer]+".txt"
}
until (($Customer
-ne "")
-and ($Backup_txt.Count -gt $Customer) -and
(0 -le $Customer) -and
($Customer -match
'[0-9]'))
$fileXPList = new-object System.IO.StreamReader($PathForXPList)
$XPList = New-Object System.Collections.ArrayList
try {
while
(($line =
$fileXPList.ReadLine())
-ne $null)
{
$line
= $line.Substring(1,$line.Substring(1).IndexOf("`""))
$XPList.Add($line) > $null
}
}
finally { $fileXPList.Close() }
$XPConvertedList = New-Object System.Collections.ArrayList
$FromXPdidntFound = New-Object System.Collections.ArrayList
$w = New-Object System.Collections.ArrayList
foreach ($Result
in $XPList)
{
$resultArr1
= findinarr
$ProgrammsForCompare $Result 0 2
if ($resultArr1 -eq
"Manual Install")
{
$w.Add("Manual
Install--" + $Result + "--`n`r") >
$null
Add-Content
"$programm_path\soft_list.txt" "Manual
Install--$Result--`n`r"
}
if ($resultArr1 -eq
"") { $FromXPdidntFound
}
$XPConvertedList.Add($resultArr1)
> $null
}
$FromXPdidntFound = $FromXPdidntFound
| Sort-Object
-Unique
$FromXPdidntFound = $FromXPdidntFound
-notlike "Update
for*"
$FromXPdidntFound = $FromXPdidntFound
-notlike "Security
Update*"
$FromXPdidntFound = $FromXPdidntFound
-notlike "Hotfix
for*"
#$FromXPdidntFound = $FromXPdidntFound -notlike
"===*"
$FromXPdidntFound = $FromXPdidntFound
-ne "List
of softwares "
$FromXPdidntFound = $FromXPdidntFound
-notlike "Windows
Genuine*"
$FromXPdidntFound = $FromXPdidntFound
-notlike "Windows
XP Service*"
$XPConvertedList = $XPConvertedList
-ne "Driver"
$XPConvertedList = $XPConvertedList
-ne "Unsupported"
$XPConvertedList = $XPConvertedList
-ne "No
longer required"
$XPConvertedList = $XPConvertedList
-notlike "Built*"
$XPConvertedList = $XPConvertedList
-ne ""
$XPConvertedList = $XPConvertedList
| Sort-Object
-Unique
$listtxt = New-Object System.Collections.ArrayList
for ($n=0; $n -lt $XPConvertedList.count;
$n++)
{
$value
= $XPConvertedList[$n]
$tmpy = findinarr $ProgrammsForCompare $value
2 3
if (($tmpy -eq "") -and
($value -ne
"==="))
{
if
($value -ne
"Manual Install")
{
Add-Content
"$programm_path\soft_list.txt" "$value`n`r"
$w.Add($value + "`n`r")
> $null
}
} else
{
$installed
= findinobj
$win7App1 $tmpy
name name
if
($installed -ne
$empty)
{ Write-Host
"******installed****** $installed"
-foregroundcolor "Green"
}
else
{
if
($tmpy -eq
"===") {$value
= $empty}
else
{
if
($tmpy -eq
"Cisco WebEx Meeting Center for Internet
Explorer")
{
$listtxt.Add("Cisco
WebEx Meeting Center for Chrome`n`r") >
$null
Add-Content
"$programm_path\soft_list.txt" "Cisco_WebEx
Meeting Center for Chrome_29.13.10.10170_x86`n`r"
}
Add-Content
"$programm_path\soft_list.txt" "$value`n`r"
$listtxt.Add("$tmpy`n`r")
> $null
}
}
}
}
Write-Host "----------------------------------------"
Write-Host "Need
to Install - " -foregroundcolor "Red"
Write-Host $w
Write-Host "$listtxt"
checkbat
No comments:
Post a Comment