Hello.
I have written 2 logon scripts and 2 logoff scripts that do roughly the same thing.
We work on VMware Horizon Non-presistent desktops, across multiple DEM environments.
In order for users to get their shortcuts in Chrome, profile.pb is exported from %appdata%\Google\Chrome\User Data\Default to a home directory.
With Firefox it’s a bit more advanced, because the Profiles directory for firefox is generated completely randomly, like mine located in %appdata%\Mozilla\Firefox\Profiles\2lmkijxd.default-release-2.
To retrieve this value, the script runs through an INI file located in %appdata%\Mozilla\Firefox\Profiles\profiles.ini.
So the scripts do almost the same, apart from extracting the value in the INI file.
Will assume that creating a function should be able to migrate both scripts to 1 script and do the same job. But I’m a bit too new to PS, and will learn how functions work.
But as of now I don’t have time, so I hope someone here can help me along the way, so I can see for myself what the new script will look like.
The imports are then correspondingly similar, with the exception of the INI file which is used to retrieve the correct firefox profile.
The scripts individually seem to work, and I see that there is a logical flaw, as I have Copy-Item in the nested IF Else statement. But I can’t get the logic to work here.
The files should be exported every time they log off (log off script) and imported every time the user logs on…
Chrome Logon Script - Import:
$COMPANYregkey = 'HKCU:\COMPANY'
$name = 'ChromeImported'
$Value = "0"
$ProfArchPath = @()
$ProfArchPath = (Get-ItemPropertyValue -Path 'HKCU:\Software\Policies\Immidio\Flex Profiles\Arguments' -Name 'ProfileArchivePath')
$File = $ProfArchPath + '\profile.pb'
$Appdata = $env:APPDATA
$FileLocation = $Appdata + '\Google\Chrome\User Data\Default'
If((Get-ItemProperty $COMPANYregkey).PSObject.Properties.Name -contains $name) {
}
Else {
New-ItemProperty -Path $COMPANYregkey -Name $name -Value $value
}
if($value -eq 1){
}
Else{
$regKey = Get-ItemProperty -Path $COMPANYregkey -Name $name
if (($regKey.ChromeImported -eq "1") -and (Test-Path -path $FileLocation)){
Copy-Item $File -Destination $FileLocation
}
Else {
If (Test-Path $FileLocation) {
Copy-Item $File -Destination $FileLocation
}
Else {
New-Item $FileLocation -ItemType Directory
Copy-Item $File -Destination $FileLocation
}
$value = "1"
Set-ItemProperty -Path $COMPANYregkey -Name $name -Value $value
}
}
Firefox Logon Script - Import
$COMPANYregkey = 'HKCU:\COMPANY'
$name = 'FirefoxImported'
$Value = "0"
$ProfArchPath = @()
$ProfArchPath = (Get-ItemPropertyValue -Path 'HKCU:\Software\Policies\Immidio\Flex Profiles\Arguments' -Name 'ProfileArchivePath')
$File = $ProfArchPath + '\places.sqlite'
$Appdata = $env:APPDATA
$INI_FileLocation = $Appdata + '\Mozilla\Firefox'
$IniFile = $INI_FileLocation + '\profiles.ini'
$AppLine = Get-Content -Path $IniFile | Where-Object { $_ -match 'Default=Profiles/' }
$Profile = $AppLine.Split('/')[1]
$FileLocation = $Appdata + '\Mozilla\Firefox\Profiles\' + $Profile + '\places.sqlite'
If((Get-ItemProperty $COMPANYregkey).PSObject.Properties.Name -contains $name) {
}
Else {
New-ItemProperty -Path $COMPANYregkey -Name $name -Value $value
}
if($value -eq 1){
}
Else{
$regKey = Get-ItemProperty -Path $COMPANYregkey -Name $name
if (($regKey.FirefoxImported -eq "1") -and (Test-Path -path $FileLocation)){
Copy-Item $File -Destination $FileLocation
}
Else {
If (Test-Path $FileLocation) {
Copy-Item $File -Destination $FileLocation
}
Else {
New-Item $FileLocation -ItemType Directory
Copy-Item $File -Destination $FileLocation
}
$value = "1"
Set-ItemProperty -Path $COMPANYregkey -Name $name -Value $value
}
}
Chrome logoff Script - Export
$ProfArchPath = @()
$ProfArchPath = (Get-ItemPropertyValue -Path 'HKCU:\Software\Policies\Immidio\Flex Profiles\Arguments' -Name 'ProfileArchivePath')
$Appdata = $env:APPDATA
$FileLocation = $Appdata + '\Google\Chrome\User Data\Default\profile.pb'
Copy-Item $FileLocation -Destination $ProfArchPath
Firefox log off script - Export:
$Appdata = $env:APPDATA
$INI_FileLocation = $Appdata + '\Mozilla\Firefox'
$IniFile = $INI_FileLocation + '\profiles.ini'
$AppLine = Get-Content -Path $IniFile | Where-Object { $_ -match 'Default=Profiles/' }
$Profile = $AppLine.Split('/')[1]
$ProfArchPath = @()
$ProfArchPath = (Get-ItemPropertyValue -Path 'HKCU:\Software\Policies\Immidio\Flex Profiles\Arguments' -Name 'ProfileArchivePath')
$BookmarkFileLocation = $INI_FileLocation + '\profiles\' + $Profile + '\places.sqlite'
Copy-Item $BookmarkFileLocation -Destination $ProfArchPath
All feedback is appreciated.
Greetings newbie