March 24, 2015 at 12:33 pm
Hi Experts
I wrote a function to see the SQL Install Features to the Grid. It's coming properly in a single column but I wanted details in two columns (for e.g first column will show the properties for e.g, Action, Features, instancename and the corresponding other column will show it's values selected / retrieved from the .INI file.
Please help me modifying the script.
function AcceptedFeatures()
{
$ACTION = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'ACTION='}
$pos = $ACTION.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $ACTION.Substring($pos+1)
$ACTION = $rightPart -replace '"', ""
$ACTION
$FEATURES = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'FEATURES='}
$pos = $FEATURES.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $FEATURES.Substring($pos+1)
$FEATURES = $rightPart -replace "`'", "`""
$FEATURES = "'" + $FEATURES +"'"
$FEATURES
$INSTALLSHAREDDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTALLSHAREDDIR='}
$pos = $INSTALLSHAREDDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTALLSHAREDDIR.Substring($pos+1)
$INSTALLSHAREDDIR = $rightPart -replace '"', ""
$INSTALLSHAREDDIR
$INSTALLSHAREDWOWDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTALLSHAREDWOWDIR='}
$pos = $INSTALLSHAREDWOWDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTALLSHAREDWOWDIR.Substring($pos+1)
$INSTALLSHAREDWOWDIR = $rightPart -replace '"', ""
$INSTALLSHAREDWOWDIR
$INSTANCENAME = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTANCENAME='}
$pos = $INSTANCENAME.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTANCENAME.Substring($pos+1)
$INSTANCENAME = $rightPart -replace '"', ""
$INSTANCENAME
$INSTANCEID = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTANCEID='}
$pos = $INSTANCEID.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTANCEID.Substring($pos+1)
$INSTANCEID = $rightPart -replace '"', ""
$INSTANCEID
$INSTANCEDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTANCEDIR='}
$pos = $INSTANCEDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTANCEDIR.Substring($pos+1)
$INSTANCEDIR = $rightPart -replace '"', ""
$INSTANCEDIR
$AGTSVCACCOUNT = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'AGTSVCACCOUNT='}
$pos = $AGTSVCACCOUNT.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $AGTSVCACCOUNT.Substring($pos+1)
$AGTSVCACCOUNT = $rightPart -replace '"', ""
$AGTSVCACCOUNT
$AGTSVCSTARTUPTYPE = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'AGTSVCSTARTUPTYPE='}
$pos = $AGTSVCSTARTUPTYPE.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $AGTSVCSTARTUPTYPE.Substring($pos+1)
$AGTSVCSTARTUPTYPE = $rightPart -replace '"', ""
$AGTSVCSTARTUPTYPE
$SQLSVCSTARTUPTYPE = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLSVCSTARTUPTYPE='}
$pos = $SQLSVCSTARTUPTYPE.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLSVCSTARTUPTYPE.Substring($pos+1)
$SQLSVCSTARTUPTYPE = $rightPart -replace '"', ""
$SQLSVCSTARTUPTYPE
$SQLCOLLATION = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLCOLLATION='}
$pos = $SQLCOLLATION.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLCOLLATION.Substring($pos+1)
$SQLCOLLATION = $rightPart -replace '"', ""
$SQLCOLLATION
$SQLSVCACCOUNT = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLSVCACCOUNT='}
$pos = $SQLSVCACCOUNT.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLSVCACCOUNT.Substring($pos+1)
$SQLSVCACCOUNT = $rightPart -replace '"', ""
$SQLSVCACCOUNT
$SQLSYSADMINACCOUNTS = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLSYSADMINACCOUNTS='}
$pos = $SQLSYSADMINACCOUNTS.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLSYSADMINACCOUNTS.Substring($pos+1)
$SQLSYSADMINACCOUNTS = $rightPart -replace '"', ""
$SQLSYSADMINACCOUNTS = """$SQLSYSADMINACCOUNTS""" -replace '\s', ', '
$SQLSYSADMINACCOUNTS
$SQLUSERDBDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLUSERDBDIR='}
$pos = $SQLUSERDBDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLUSERDBDIR.Substring($pos+1)
$SQLUSERDBDIR = $rightPart -replace '"', ""
$SQLUSERDBDIR
$SQLUSERDBLOGDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLUSERDBLOGDIR='}
$pos = $SQLUSERDBLOGDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLUSERDBLOGDIR.Substring($pos+1)
$SQLUSERDBLOGDIR = $rightPart -replace '"', ""
$SQLUSERDBLOGDIR
$SQLTEMPDBDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLTEMPDBDIR='}
$pos = $SQLTEMPDBDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLTEMPDBDIR.Substring($pos+1)
$SQLTEMPDBDIR = $rightPart -replace '"', ""
$SQLTEMPDBDIR
$TCPENABLED = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'TCPENABLED='}
$pos = $TCPENABLED.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $TCPENABLED.Substring($pos+1)
$TCPENABLED = $rightPart -replace '"', ""
IF ($TCPENABLED -eq 0)
{
#Print $TCPENABLED
Write-Host "Disabled"
}
ELSEIF($TCPENABLED -eq 1)
{
#Print $TCPENABLED
Write-Host "Enabled"
}$TCPENABLED
<#$ACTION
$FEATURES
$INSTALLSHAREDDIR
$INSTALLSHAREDWOWDIR
$INSTANCENAME
$INSTANCENAME
$INSTANCEDIR
$AGTSVCACCOUNT
$AGTSVCSTARTUPTYPE
$SQLSVCSTARTUPTYPE
$SQLCOLLATION
$SQLSVCACCOUNT
$SQLSYSADMINACCOUNTS
$SQLUSERDBDIR
$SQLUSERDBLOGDIR
$SQLTEMPDBDIR
$TCPENABLED#>
#$values = $ACTION
#$values = + $FEATURES
#$values = + $INSTALLSHAREDDIR
#$values = + $INSTALLSHAREDWOWDIR
#$values = + $INSTANCENAME
#$values = + [string] $INSTANCENAME
#$values = + $INSTANCEDIR
#$values = + $AGTSVCACCOUNT
#$values = + $AGTSVCSTARTUPTYPE
#$values = + $SQLSVCSTARTUPTYPE
#$values = + $SQLCOLLATION
#$values = + $SQLSVCACCOUNT
#$values = + $SQLSYSADMINACCOUNTS
#$values = + $SQLUSERDBDIR
#$values = + $SQLUSERDBDIR
#$values = + $SQLUSERDBDIR
#$values = + $SQLUSERDBLOGDIR
#$values = + $SQLTEMPDBDIR
#$values = + $TCPENABLED
}
AcceptedFeatures | out-gridview -wait
Thanks.
March 25, 2015 at 8:13 am
PowerShell 3.0 works this way:
# Create an array.
$features = @()
# Add a value to display.
$features += [PsCustomObject]@{
Property = "Example"
Value = "1.0"
}
# Add a value to display.
$features += [PsCustomObject]@{
Property = "TextValue"
Value = "ABC"
}
# Display the values.
$features | Out-GridView
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 25, 2015 at 9:02 am
Many thanks, Gary!
Thanks.
March 25, 2015 at 9:27 am
Hi Gary
Does this Out-gridview page offer any OK button to close the screen?
Thanks
Sourav
Thanks.
March 25, 2015 at 11:05 am
HI Gary
Please check my modified script using functions.
cls
function AcceptedFeatures()
{
$ACTION = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'ACTION='}
$pos = $ACTION.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $ACTION.Substring($pos+1)
$ACTION = $rightPart -replace '"', ""
$ACTION
$FEATURES = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'FEATURES='}
$pos = $FEATURES.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $FEATURES.Substring($pos+1)
#$FEATURES = $rightPart -replace "`'", "`""
#$FEATURES = "'" + $FEATURES +"'"
$FEATURES
$INSTALLSHAREDDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTALLSHAREDDIR='}
$pos = $INSTALLSHAREDDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTALLSHAREDDIR.Substring($pos+1)
$INSTALLSHAREDDIR = $rightPart -replace '"', ""
$INSTALLSHAREDDIR
$INSTALLSHAREDWOWDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTALLSHAREDWOWDIR='}
$pos = $INSTALLSHAREDWOWDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTALLSHAREDWOWDIR.Substring($pos+1)
$INSTALLSHAREDWOWDIR = $rightPart -replace '"', ""
$INSTALLSHAREDWOWDIR
$INSTANCENAME = 'INST30'
$INSTANCEID = 'INST30'
$INSTANCEDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'INSTANCEDIR='}
$pos = $INSTANCEDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $INSTANCEDIR.Substring($pos+1)
$INSTANCEDIR = $rightPart -replace '"', ""
$INSTANCEDIR
$AGTSVCACCOUNT = 'AGT\ACC$30'
$AGTSVCSTARTUPTYPE = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'AGTSVCSTARTUPTYPE='}
$pos = $AGTSVCSTARTUPTYPE.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $AGTSVCSTARTUPTYPE.Substring($pos+1)
$AGTSVCSTARTUPTYPE = $rightPart -replace '"', ""
$AGTSVCSTARTUPTYPE
$SQLSVCSTARTUPTYPE = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLSVCSTARTUPTYPE='}
$pos = $SQLSVCSTARTUPTYPE.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLSVCSTARTUPTYPE.Substring($pos+1)
$SQLSVCSTARTUPTYPE = $rightPart -replace '"', ""
$SQLSVCSTARTUPTYPE
$SQLCOLLATION = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLCOLLATION='}
$pos = $SQLCOLLATION.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLCOLLATION.Substring($pos+1)
$SQLCOLLATION = $rightPart -replace '"', ""
$SQLCOLLATION
$SQLSVCACCOUNT ='AGT\vts07'
$SQLSYSADMINACCOUNTS = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLSYSADMINACCOUNTS='}
$pos = $SQLSYSADMINACCOUNTS.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $SQLSYSADMINACCOUNTS.Substring($pos+1)
$SQLSYSADMINACCOUNTS = $rightPart -replace '"', ""
$SQLSYSADMINACCOUNTS = """$SQLSYSADMINACCOUNTS""" -replace '\s', ', '
$SQLSYSADMINACCOUNTS
$INSTANCENAME = 'INST30'
$SQLUSERDBDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLUSERDBDIR='}
#$SQLTEMPDBDIR = $SQLTEMPDBDIR -replace '"', ""
$pos = $SQLUSERDBDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$SQLUSERDBDIR1 = $SQLUSERDBDIR.Substring($pos+1)
$SQLUSERDBDIR1 = $SQLUSERDBDIR1 -replace '"', ""
$SQLUSERDBDIR = $SQLUSERDBDIR1 +'\'+$INSTANCENAME
$SQLUSERDBDIR
$INSTANCENAME = 'INST30'
#SQLUSERDBLOGDIR PATH
$SQLUSERDBLOGDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLUSERDBLOGDIR='}
#$SQLTEMPDBDIR = $SQLTEMPDBDIR -replace '"', ""
$pos = $SQLUSERDBLOGDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$SQLUSERDBLOGDIR1 = $SQLUSERDBLOGDIR.Substring($pos+1)
$SQLUSERDBLOGDIR1 = $SQLUSERDBLOGDIR1 -replace '"', ""
$SQLUSERDBLOGDIR = $SQLUSERDBLOGDIR1 +'\'+$INSTANCENAME
$SQLUSERDBLOGDIR
#Tempdb path
$SQLTEMPDBDIR = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'SQLTEMPDBDIR='}
#$SQLTEMPDBDIR = $SQLTEMPDBDIR -replace '"', ""
$pos = $SQLTEMPDBDIR.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$SQLTEMPDBDIR1 = $SQLTEMPDBDIR.Substring($pos+1)
$SQLTEMPDBDIR1 = $SQLTEMPDBDIR1 -replace '"', ""
$SQLTEMPDBDIR = $SQLTEMPDBDIR1 +'\'+$INSTANCENAME
$SQLTEMPDBDIR
$TCPENABLED = Get-Content "C:\test\SQLServer2012ConfigurationFile_Install.ini" | Where-Object {$_ -match 'TCPENABLED='}
$pos = $TCPENABLED.IndexOf("=")
#$leftPart = $SQLSVCACCOUNT.Substring(0, $pos)
$rightPart = $TCPENABLED.Substring($pos+1)
$TCPENABLED = $rightPart -replace '"', ""
<#IF ($TCPENABLED -eq 0)
{
#Print $TCPENABLED
Write-Host "Disabled"
}
ELSEIF($TCPENABLED -eq 1)
{
#Print $TCPENABLED
Write-Host "Enabled"
}#>
$TCPENABLED
write-host ".............17 selected features during SQL Install............."
$hash = @{
ACTION = $ACTION
FEATURES = $FEATURES
INSTALLSHAREDDIR = $INSTALLSHAREDDIR
INSTALLSHAREDWOWDIR = $INSTALLSHAREDWOWDIR
INSTANCENAME = $INSTANCENAME
INSTANCEID = $INSTANCEID
INSTANCEDIR = $INSTANCEDIR
AGTSVCACCOUNT = $AGTSVCACCOUNT
AGTSVCSTARTUPTYPE = $AGTSVCSTARTUPTYPE
SQLSVCSTARTUPTYPE = $SQLSVCSTARTUPTYPE
SQLCOLLATION = $SQLCOLLATION
SQLSVCACCOUNT = $SQLSVCACCOUNT
SQLSYSADMINACCOUNTS = $SQLSYSADMINACCOUNTS
SQLUSERDBDIR = $SQLUSERDBDIR
SQLUSERDBLOGDIR = $SQLUSERDBLOGDIR
SQLTEMPDBDIR = $SQLTEMPDBDIR
TCPENABLED = $TCPENABLED
}
$Object = New-Object PSObject -Property $hash
$Object
write-host ".......................END OF SELECTION......................."
}
function ShowinOutGrid()
{
<#$ACTION
$FEATURES
$INSTALLSHAREDDIR
$INSTALLSHAREDWOWDIR
$INSTANCENAME
$INSTANCEID
$INSTANCEDIR
$AGTSVCACCOUNT
$AGTSVCSTARTUPTYPE
$SQLSVCSTARTUPTYPE
$SQLCOLLATION
$SQLSVCACCOUNT
$SQLSYSADMINACCOUNTS
$SQLUSERDBDIR
$SQLUSERDBLOGDIR
$SQLTEMPDBDIR
$TCPENABLED
#>
#$List1 = "";
$List1 = @()
$List1 += [pscustomobject]@{
Property = "Action"
Value = $ACTION
}
$List1 += [pscustomobject]@{
Property = "INSTALLSHAREDDIR"
Value = $INSTALLSHAREDDIR
}
$List1 += [pscustomobject]@{
Property = "INSTALLSHAREDWOWDIR"
Value = $INSTALLSHAREDWOWDIR
}
$List1 += [pscustomobject]@{
Property = "INSTALLSHAREDWOWDIR"
Value = $INSTALLSHAREDWOWDIR
}
$List1 += [pscustomobject]@{
Property = "INSTANCENAME"
Value = $INSTANCENAME
}
$List1 += [pscustomobject]@{
Property = "INSTANCEID"
Value = $INSTANCEID
}
$List1 += [pscustomobject]@{
Property = "INSTANCEDIR"
Value = $INSTANCEDIR
}
$List1 += [pscustomobject]@{
Property = "AGTSVCACCOUNT"
Value = $AGTSVCACCOUNT
}
$List1 += [pscustomobject]@{
Property = "AGTSVCSTARTUPTYPE"
Value = $AGTSVCSTARTUPTYPE
}
$List1 += [pscustomobject]@{
Property = "SQLSVCSTARTUPTYPE"
Value = $SQLSVCSTARTUPTYPE
}
$List1 += [pscustomobject]@{
Property = "SQLCOLLATION"
Value = $SQLCOLLATION
}
$List1 += [pscustomobject]@{
Property = "SQLSVCACCOUNT"
Value = $SQLSVCACCOUNT
}
$List1 += [pscustomobject]@{
Property = "SQLSYSADMINACCOUNTS"
Value = $SQLSYSADMINACCOUNTS
}
$List1 += [pscustomobject]@{
Property = "SQLUSERDBDIR"
Value = $SQLUSERDBDIR
}
$List1 += [pscustomobject]@{
Property = "SQLUSERDBLOGDIR"
Value = $SQLUSERDBLOGDIR
}
$List1 += [pscustomobject]@{
Property = "SQLTEMPDBDIR"
Value = $SQLTEMPDBDIR
}
$List1 += [pscustomobject]@{
Property = "TCPENABLED"
Value = $TCPENABLED
}
$List1 | Out-GridView -wait
}
## MAIN ##
AcceptedFeatures
ShowinOutGrid
Thanks.
March 26, 2015 at 1:10 am
SQL-DBA-01 (3/25/2015)
Hi GaryDoes this Out-gridview page offer any OK button to close the screen?
Thanks
Sourav
No idea. Experiment and let us know 😉
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 27, 2015 at 6:41 am
Does this Out-gridview page offer any OK button to close the screen?
No - you will need to create your own DataGridView in order to have buttons, highlighting, etc. and you will need to write all the code for the design and loading of the grid. If you want to do forms using Powershell, you may want to look into a tool like Sapiens' Powershell Suite. It will save a lot of coding.
MG
"There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies."
Tony Hoare
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply