If you want do e.g. save Settings of your script, you have multiple ways to do so. For my Powershell Toolkit, i decided to use CSV Export and Import, because it is very easy to implement.

Export:

$folderbrowserdialog1.ShowDialog()
$save = $folderbrowserdialog1.SelectedPath += “/config.csv”
New-Object -TypeName PSCustomObject -Property @{
“global:Language” = $Language
“global:Profilefolder” = $Profilefolder
“global:Homefolder” = $Homefolder
“global:Outfile” = $Outfile
“global:SiteName” = $SiteName
“global:SCCMServer” = $SCCMServer
“global:SCCMNameSpace” = $SCCMNameSpace
} | Export-Csv -Path $save -NoTypeInformation -Force

I Use Powershellstudio for GUI implementing. It is very intiutive to use. If you don’t have it, you can make a Folderbrowser Dialog like this:

$app = new-object -com Shell.Application
$folder = $app.BrowseForFolder(0, “Select Folder”, 0, “C:\”)

Second, I add the filename with:

$save = $folderbrowserdialog1.SelectedPath += "/config.csv"

Now you have to create a custom Powershell Object for your Export. And you have to give your variables names for the CSV. If you want to Import the CSV later, I recommend to use the Variable Names, if you use it for something else, Excel maybe, you can change the names as you wish.

New-Object -TypeName PSCustomObject -Property @{
“global:Language” = $Language
“global:Profilefolder” = $Profilefolder
“global:Homefolder” = $Homefolder
“global:Outfile” = $Outfile
“global:SiteName” = $SiteName
“global:SCCMServer” = $SCCMServer
“global:SCCMNameSpace” = $SCCMNameSpace
}

At last, we export the whole custom object in our CSV-File.

Export-Csv -Path $save -NoTypeInformation -Force

Import

Now for the import, it is pretty much the same but the other way around.

$openfiledialog1.ShowDialog()
$load = $openfiledialog1.FileNames
$Import = Import-Csv -Path $load
foreach ($Line in $Import) {
$global:Language=$($Line.“global:Language”)
$global:Profilefolder=$($Line.“global:Profilefolder”)
$global:Homefolder=$($Line.“global:Homefolder”)
$global:Outfile=$($Line.“global:Outfile”)
$global:SiteName=$($Line.“global:SiteName”)
$global:SCCMServer=$($Line.“global:SCCMServer”)
$global:SCCMNameSpace=$($Line.“global:SCCMNameSpace”)
$global:SCCMEnabled=[bool]$($Line.“global:SCCMEnabled”)
}

 

Openfiledialog opens a File Browser, where you can select your config file. Here is how you can do it without Powershell Studio:

[void] [Reflection.Assembly]::LoadWithPartialName( ‘System.Windows.Forms’ )
$d = New-Object Windows.Forms.OpenFileDialog
$d.ShowHelp = $true
$d.ShowDialog()

Now the Import itself:

$Import = Import-Csv -Path $load
foreach ($Line in $Import) {
$global:Language=$($Line.“global:Language”)
$global:Profilefolder=$($Line.“global:Profilefolder”)
$global:Homefolder=$($Line.“global:Homefolder”)
$global:Outfile=$($Line.“global:Outfile”)
$global:SiteName=$($Line.“global:SiteName”)
$global:SCCMServer=$($Line.“global:SCCMServer”)
$global:SCCMNameSpace=$($Line.“global:SCCMNameSpace”)
$global:SCCMEnabled=[bool]$($Line.“global:SCCMEnabled”)
}

You have to import the CSV into a variable, then check each Item for your given Title, e.g. “global.Language” The $ and Brackets are needed.

That’s all for the Import / Export I am using in Powershell Toolkit