Skip to content

Instantly share code, notes, and snippets.

@wiking-at
Created October 13, 2014 21:51
Show Gist options
  • Save wiking-at/a276d32211bb8228fe08 to your computer and use it in GitHub Desktop.
Save wiking-at/a276d32211bb8228fe08 to your computer and use it in GitHub Desktop.
Convert Inidb to SQL
Function Get-IniContent
{
<#
.Synopsis
Gets the content of an INI file
.Description
Gets the content of an INI file and returns it as a hashtable
.Notes
Author : Oliver Lipkau <[email protected]>
Blog : http://oliver.lipkau.net/blog/
Date : 2014/06/23
Version : 1.1
#Requires -Version 2.0
.Inputs
System.String
.Outputs
System.Collections.Hashtable
.Parameter FilePath
Specifies the path to the input file.
.Example
$FileContent = Get-IniContent "C:\myinifile.ini"
-----------
Description
Saves the content of the c:\myinifile.ini in a hashtable called $FileContent
.Example
$inifilepath | $FileContent = Get-IniContent
-----------
Description
Gets the content of the ini file passed through the pipe into a hashtable called $FileContent
.Example
C:\PS>$FileContent = Get-IniContent "c:\settings.ini"
C:\PS>$FileContent["Section"]["Key"]
-----------
Description
Returns the key "Key" of the section "Section" from the C:\settings.ini file
.Link
Out-IniFile
#>
[CmdletBinding()]
Param(
[ValidateNotNullOrEmpty()]
[ValidateScript({(Test-Path $_) -and ((Get-Item $_).Extension -eq ".ini")})]
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
[string]$FilePath
)
Begin
{Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"}
Process
{
Write-Verbose "$($MyInvocation.MyCommand.Name):: Processing file: $Filepath"
$ini = @{}
switch -regex -file $FilePath
{
"^\[(.+)\]$" # Section
{
$section = $matches[1]
$ini[$section] = @{}
$CommentCount = 0
}
"^(;.*)$" # Comment
{
if (!($section))
{
$section = "No-Section"
$ini[$section] = @{}
}
$value = $matches[1]
$CommentCount = $CommentCount + 1
$name = "Comment" + $CommentCount
$ini[$section][$name] = $value
}
"(.+?)\s*=\s*(.*)" # Key
{
if (!($section))
{
$section = "No-Section"
$ini[$section] = @{}
}
$name,$value = $matches[1..2]
$ini[$section][$name] = $value
}
}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $path"
Return $ini
}
End
{Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"}
}
Set-Location F:\Server1\db
#$query = (dir -include *.ini -recurse | select-string 'bankmoney' )
$query = (dir -include *.ini -recurse | select-string 'wiking' )
#$query.Path
#todo - build for loop to create the sql import file
$iniconent = Get-IniContent $query.path
$uid = $iniconent["Playerinfo"][“UID”]
$name = $iniconent["Playerinfo"][“Name”]
$lastside = $iniconent["Playerinfo"][“LastSide”]
$bankmoney = $iniconent["Playerinfo"][“BankMoney”]
"insert into table values $uid, $name, $lastside, $bankmoney"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment