PowershellMadness
Wednesday, October 17, 2012
EZ Powershell Services Monitor
# EZ Service Monitor
# By Nigel Glenwood
$myserviceName = "Adaptive Brightness"
$objectServices = get-service -Computername localhost | Where-Object {$_.DisplayName -eq $myserviceName} | Select Name, Status, DisplayName
$objectServices | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The Status of Service is $_.Status
write-host The displayname $_.DisplayName
if ($_.Status -eq "Stopped")
{
write-host "Warning The Service is Stopped " -BackgroundColor Red
}
elseif ($_.Status -eq "Running")
{
write-host "The service is jogging and running healthy it is in good shape" -BackgroundColor Green
}
}
Friday, September 21, 2012
Split
$tempresult = $Subject[$i].Substring(3,50)
# get rid of first 3 CN=
$tempresult.split(":")
Friday, March 9, 2012
Converting commands easily to nice XML
# Retrieve all hot fixes and output into standard XML type file test.xml
(Get-hotfix ConvertTo-XML).Save("C:\temp\Test.xml")
(Get-hotfix ConvertTo-XML).Save("C:\temp\Test.xml")
Tuesday, November 1, 2011
Real Time Services Analyzer
# Change Log
# NTG 1/28/2010 Adjusted to send email to XXXXXXXXXXXXXXXX
# th 2/1/2010 = no change here but added eurestis@microsoft.com to sp_emailb in MSDB \\bakerx as
# copy recipent
#######################################################
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
cls
$mydate = Get-Date
Write-Host "The Date is $mydate"
sleep 2
Write-Host "#####################################" -foregroundcolor red -backgroundcolor green
Write-Host "# #"-foregroundcolor red -backgroundcolor blue
Write-Host "# Real-Time Services Analyzer #"-foregroundcolor red -backgroundcolor black
Write-Host "# By: Nigel Glenwood #"-foregroundcolor red -backgroundcolor blue
Write-Host "#####################################"-foregroundcolor red -backgroundcolor green
# Write-Host "Name, ID, FS, FreeSpace, Size, Usedspace"-foregroundcolor white -backgroundcolor blue
# Nigel Notes
write Services Status > smnigel4.html
#
# first get-content grabs the filenames that contains the servers for each space
# Then for each space, run through that file name and grab all the servers and send alerts as needed.
# So basically, these are kind of loops inside of loops.
# -Nigel
# beginning of outmost loop
#get-content d:\mumar\thefilenames.txt | Foreach-Object {
#write-host $_ is the value I just read let me throw that into a variable for me
#$filetoprocess=$_
#write-host $filetoprocess is the file I am going to process now
# above works like . does not work
#Invoke-Expression -ComputerName aitpsql511 -Command 'get-service'
#$svc={Param ([string]$computer=$env:computername,
# [string]$name="*")
# [system.serviceprocess.servicecontroller]::GetServices($computer) |
# where {$_.name -like $name}
# }
# now run it
#&$svc "aitpsql511"
# above works like sh*t.. does not work
get-content web1servers.txt | ForEach-Object {
$servername=$_
# get-wmiobject win32_service -computer $servername | Select *
get-wmiobject win32_service -filter "StartMode like '%Auto%' and Name like '%ProcurementServiceHost%' " -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write-host $_.Name $_.State, $Servername is in a BAD State -backgroundcolor red
write $_.Name $_.State, $Servername is in a BAD State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
}
}
$monitored='ProcurementServicesHost'
get-content web1services.txt | ForEach-Object {
$servicename=$_
write-host I have just read the value for service name as $servicename, checking on that service now
# get-wmiobject win32_service -computer $servername | Select *
# -filter "Name='Revelation LSS Provider' "a
# -filter "Name like '%LSR%'"
get-wmiobject win32_service -filter "Name like '%$servicename%'" -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
$monitored=$monitored+$_.name+$_.State
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write $_.Name $_.State, $Servername is in a STOPPED State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
write-host got to here dude
}
}
}
}
$the_date=get-date
write-host Completed at: $the_date >> smnigel4.html
sleep 5
# beginner of inner loop
#get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer (get-content $filetoprocess'.txt') | Select #SystemName,DeviceID,FileSystem,@{Name="Freespace";Expression={([Math]::round([long]$_.FreeSpace/1gb,0))}},@{Name="FreespaceM#e#gs";Expression={([Math]::round([long]$_.FreeSpace/1mb,0))}},@{Name="Size";Expression={([Math]::round([long]$_.Size/1gb,0))}}#,#@{Name="Usedspace";Expression={([Math]::round([long]$_.Size/1gb-[long]$_.FreeSpace/1gb,0))}} | ForEach-Object {
# -filter "StartupType like '%Auto%'"
# This will send an email to Nigel that it ran, so every 5 minutes, can be used to troubleshoot
# or to ensure it is running correctly through scheduler
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The csprob1 Services Check ran State, $_.Name $monitored','dddlen', '$servername'"
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The SERVER Services Check ran State, $_.Name $monitored ','mddddddn', '$servername'"
# NTG 1/28/2010 Adjusted to send email to XXXXXXXXXXXXXXXX
# th 2/1/2010 = no change here but added eurestis@microsoft.com to sp_emailb in MSDB \\bakerx as
# copy recipent
#######################################################
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
cls
$mydate = Get-Date
Write-Host "The Date is $mydate"
sleep 2
Write-Host "#####################################" -foregroundcolor red -backgroundcolor green
Write-Host "# #"-foregroundcolor red -backgroundcolor blue
Write-Host "# Real-Time Services Analyzer #"-foregroundcolor red -backgroundcolor black
Write-Host "# By: Nigel Glenwood #"-foregroundcolor red -backgroundcolor blue
Write-Host "#####################################"-foregroundcolor red -backgroundcolor green
# Write-Host "Name, ID, FS, FreeSpace, Size, Usedspace"-foregroundcolor white -backgroundcolor blue
# Nigel Notes
write Services Status > smnigel4.html
#
# first get-content grabs the filenames that contains the servers for each space
# Then for each space, run through that file name and grab all the servers and send alerts as needed.
# So basically, these are kind of loops inside of loops.
# -Nigel
# beginning of outmost loop
#get-content d:\mumar\thefilenames.txt | Foreach-Object {
#write-host $_ is the value I just read let me throw that into a variable for me
#$filetoprocess=$_
#write-host $filetoprocess is the file I am going to process now
# above works like . does not work
#Invoke-Expression -ComputerName aitpsql511 -Command 'get-service'
#$svc={Param ([string]$computer=$env:computername,
# [string]$name="*")
# [system.serviceprocess.servicecontroller]::GetServices($computer) |
# where {$_.name -like $name}
# }
# now run it
#&$svc "aitpsql511"
# above works like sh*t.. does not work
get-content web1servers.txt | ForEach-Object {
$servername=$_
# get-wmiobject win32_service -computer $servername | Select *
get-wmiobject win32_service -filter "StartMode like '%Auto%' and Name like '%ProcurementServiceHost%' " -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write-host $_.Name $_.State, $Servername is in a BAD State -backgroundcolor red
write $_.Name $_.State, $Servername is in a BAD State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
}
}
$monitored='ProcurementServicesHost'
get-content web1services.txt | ForEach-Object {
$servicename=$_
write-host I have just read the value for service name as $servicename, checking on that service now
# get-wmiobject win32_service -computer $servername | Select *
# -filter "Name='Revelation LSS Provider' "a
# -filter "Name like '%LSR%'"
get-wmiobject win32_service -filter "Name like '%$servicename%'" -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
$monitored=$monitored+$_.name+$_.State
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write $_.Name $_.State, $Servername is in a STOPPED State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
write-host got to here dude
}
}
}
}
$the_date=get-date
write-host Completed at: $the_date >> smnigel4.html
sleep 5
# beginner of inner loop
#get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer (get-content $filetoprocess'.txt') | Select #SystemName,DeviceID,FileSystem,@{Name="Freespace";Expression={([Math]::round([long]$_.FreeSpace/1gb,0))}},@{Name="FreespaceM#e#gs";Expression={([Math]::round([long]$_.FreeSpace/1mb,0))}},@{Name="Size";Expression={([Math]::round([long]$_.Size/1gb,0))}}#,#@{Name="Usedspace";Expression={([Math]::round([long]$_.Size/1gb-[long]$_.FreeSpace/1gb,0))}} | ForEach-Object {
# -filter "StartupType like '%Auto%'"
# This will send an email to Nigel that it ran, so every 5 minutes, can be used to troubleshoot
# or to ensure it is running correctly through scheduler
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The csprob1 Services Check ran State, $_.Name $monitored','dddlen', '$servername'"
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The SERVER Services Check ran State, $_.Name $monitored ','mddddddn', '$servername'"
Monitor disk Usage
rem Nigel Glenwood Disk Monitoring using SP
rem create startup file first so we can log results of script
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe d:\mumar\monitor5.ps1
echo ran at this time %DATE% %TIME% > monitor_log.txt
Call the above drive_start.cmd or something tlike that… ensure the path points to your executable of powershell.
This calls the Powershell noted below, but first:
For the below to work create Files of your servers, and name the file name the support DL to get notified when thresholds are breached.
So for example:
CSPA.txt
PFOPS.txt
PHOPS.TXT
Lenel.txt
Within each file have a list of the servers you want monitored.
Next, create a file called: thefilenames, and place just the DL names in there so for above it would be
Cspa
Pfops
Phops
Lenel
Then within SQL server, create an exec sp_email, that will accept the parameters I send below, in the end, I pass the filename which is also the DL which the email will go to.
A Sample SP and the one I use is as follows:
-- =============================================
CREATE PROCEDURE [dbo].[sp_email]
-- Add the parameters for the stored procedure here
@p1 varchar(800) = 'Body not supplied to sp sp_email on bakerx',
@p2 varchar(40),
@p3 varchar(40)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @thebody varchar(800)
declare @recips varchar(40)
declare @servername varchar(200)
-- Insert statements for procedure here
set @thebody = @p1 + ' This alert came from bakerx. sp_email from within MSDB '
set @recips = @p2 +'@microsoft.com'
--set @recips = 'niglen@microsoft.com'
set @servername = @p3+' <> <<>>'
set @thebody = @thebody + '
'
exec sp_send_dbmail @profile_name = 'svcoad',
@recipients = @recips,
@subject = @servername,
@body = @thebody,
@copy_recipients = 'niglen@microsoft.com',
@body_format = 'HTML'
--;xxxxxx@microsoft.com;xxxxxxnbu@microsoft.com;thxxxxxdie@microsoft.com;xxxeets@microsoft.com;shxxxxpavi@microsoft.com;xxxxxnw@microsoft.com',
END
The main powershell is below, the comments should explain pretty good how it works.
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
cls
$mydate = Get-Date
Write-Host "The Date is $mydate"
sleep 2
Write-Host "#####################################" -foregroundcolor red -backgroundcolor yellow
Write-Host "# #"-foregroundcolor red -backgroundcolor yellow
Write-Host "# Real-Time Disk Analyzer #"-foregroundcolor red -backgroundcolor yellow
Write-Host "# By: Nigel Glenwood #"-foregroundcolor red -backgroundcolor yellow
Write-Host "#####################################"-foregroundcolor red -backgroundcolor yellow
# Write-Host "Name, ID, FS, FreeSpace, Size, Usedspace"-foregroundcolor white -backgroundcolor blue
#
# first get-content grabs the filenames that contains the servers for each space
# Then for each space, run through that file name and grab all the servers and send alerts as needed.
# So basically, these are kind of loops inside of loops.
# -Nigel
# beginning of outmost loop
get-content d:\mumar\thefilenames.txt | Foreach-Object {
write-host $_ is the value I just read let me throw that into a variable for me
$filetoprocess=$_
write-host $filetoprocess is the file I am going to process now
sleep 5
# beginner of inner loop
get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer (get-content $filetoprocess'.txt') | Select SystemName,DeviceID,FileSystem,@{Name="Freespace";Expression={([Math]::round([long]$_.FreeSpace/1gb,0))}},@{Name="FreespaceMegs";Expression={([Math]::round([long]$_.FreeSpace/1mb,0))}},@{Name="Size";Expression={([Math]::round([long]$_.Size/1gb,0))}},@{Name="Usedspace";Expression={([Math]::round([long]$_.Size/1gb-[long]$_.FreeSpace/1gb,0))}} | ForEach-Object {
# calculcate percent Free
$percentage=([Math]::round([long]$_.FreeSpace/[long]$_.size,2))
# remove decimals, make it look pretty
$percentage_free=$percentage*100
$the_system_name=$_.SystemName
$free_space=$_.FreeSpace
$free_space_megs=$_.FreeSpaceMegs
$drive_letter=$_.deviceid
write-host "driver letter is: "
write-host $drive_letter
# find files written to within 1 day
#if ($drive_letter -eq 'E:')
#{
# write-host "drive letter does = E running analysis"
# $DateToCompare = (Get-date).AddDays(-1)
# $Dir = get-childitem \\$the_system_name\E$ -recurse | where {$_.lastwritetime -gt $datetocompare}
# write-host "Directory is" $Dir
# $List = | format-table
# $list | format-table name
#, lastwritetime, length
#write-host $list
#write-host $Dir
#write-host "above is the list"
#sleep 5
#}
#write-host "did it write data above of the files?"
#sleep 2
# Nigel Notes, have to put the variables into different variables otherwise for some reason
# they will print all data just for one of the fields, so trying to just display percent free space results
# in all the fields showing
Write-Host $_.SystemName $_.DeviceID $_.FileSystem "FreeSpace:" $_.FreeSpace ", Actual Size:" $_.Size, "Percentage Free" $percentage_free -foreground white -backgroundcolor magenta
if ($percentage_free -lt 3)
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_email 'Server: $the_system_name, Percentage of Free Disk Space Left is: $percentage_free PERCENT, Free Unused Space is: $free_space GIGS, Free Unused Space: $free_space_megs MEGS DETAILS:$_.SystemName Time of Discovery: $mydate ... Less than 3 percent Free ... ','$filetoprocess', '$the_system_name'"
}
elseif ($percentage_free -lt 7)
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_email 'Server: $the_system_name Percentage of Free Disk Space Left is: $percentage_free PERCENT Free Unused Space is: $free_space Gigs , Free Unused Space: $free_space_megs MEGS DETAILS: $_.SystemName Time of Discovery: $mydate ... less than 5 Percent Free ... ','$filetoprocess','$the_system_name'"
Write-Host "Sending Email.... less than 5 percent free"
}
}
# end of inner loop
}
# end of outter loop
Write-Host "COMPLETE......................"
# send an email to Nigel to let me know that it at least ran, even if no thresholds were breached
sqlcmd /S bakerx /E -d msdb /Q "exec sp_email5 'Completed AT : %DATE% %TIME%"
Nigel
rem create startup file first so we can log results of script
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe d:\mumar\monitor5.ps1
echo ran at this time %DATE% %TIME% > monitor_log.txt
Call the above drive_start.cmd or something tlike that… ensure the path points to your executable of powershell.
This calls the Powershell noted below, but first:
For the below to work create Files of your servers, and name the file name the support DL to get notified when thresholds are breached.
So for example:
CSPA.txt
PFOPS.txt
PHOPS.TXT
Lenel.txt
Within each file have a list of the servers you want monitored.
Next, create a file called: thefilenames, and place just the DL names in there so for above it would be
Cspa
Pfops
Phops
Lenel
Then within SQL server, create an exec sp_email, that will accept the parameters I send below, in the end, I pass the filename which is also the DL which the email will go to.
A Sample SP and the one I use is as follows:
-- =============================================
CREATE PROCEDURE [dbo].[sp_email]
-- Add the parameters for the stored procedure here
@p1 varchar(800) = 'Body not supplied to sp sp_email on bakerx',
@p2 varchar(40),
@p3 varchar(40)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @thebody varchar(800)
declare @recips varchar(40)
declare @servername varchar(200)
-- Insert statements for procedure here
set @thebody = @p1 + ' This alert came from bakerx. sp_email from within MSDB '
set @recips = @p2 +'@microsoft.com'
--set @recips = 'niglen@microsoft.com'
set @servername = @p3+' <
set @thebody = @thebody + '
exec sp_send_dbmail @profile_name = 'svcoad',
@recipients = @recips,
@subject = @servername,
@body = @thebody,
@copy_recipients = 'niglen@microsoft.com',
@body_format = 'HTML'
--;xxxxxx@microsoft.com;xxxxxxnbu@microsoft.com;thxxxxxdie@microsoft.com;xxxeets@microsoft.com;shxxxxpavi@microsoft.com;xxxxxnw@microsoft.com',
END
The main powershell is below, the comments should explain pretty good how it works.
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
cls
$mydate = Get-Date
Write-Host "The Date is $mydate"
sleep 2
Write-Host "#####################################" -foregroundcolor red -backgroundcolor yellow
Write-Host "# #"-foregroundcolor red -backgroundcolor yellow
Write-Host "# Real-Time Disk Analyzer #"-foregroundcolor red -backgroundcolor yellow
Write-Host "# By: Nigel Glenwood #"-foregroundcolor red -backgroundcolor yellow
Write-Host "#####################################"-foregroundcolor red -backgroundcolor yellow
# Write-Host "Name, ID, FS, FreeSpace, Size, Usedspace"-foregroundcolor white -backgroundcolor blue
#
# first get-content grabs the filenames that contains the servers for each space
# Then for each space, run through that file name and grab all the servers and send alerts as needed.
# So basically, these are kind of loops inside of loops.
# -Nigel
# beginning of outmost loop
get-content d:\mumar\thefilenames.txt | Foreach-Object {
write-host $_ is the value I just read let me throw that into a variable for me
$filetoprocess=$_
write-host $filetoprocess is the file I am going to process now
sleep 5
# beginner of inner loop
get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer (get-content $filetoprocess'.txt') | Select SystemName,DeviceID,FileSystem,@{Name="Freespace";Expression={([Math]::round([long]$_.FreeSpace/1gb,0))}},@{Name="FreespaceMegs";Expression={([Math]::round([long]$_.FreeSpace/1mb,0))}},@{Name="Size";Expression={([Math]::round([long]$_.Size/1gb,0))}},@{Name="Usedspace";Expression={([Math]::round([long]$_.Size/1gb-[long]$_.FreeSpace/1gb,0))}} | ForEach-Object {
# calculcate percent Free
$percentage=([Math]::round([long]$_.FreeSpace/[long]$_.size,2))
# remove decimals, make it look pretty
$percentage_free=$percentage*100
$the_system_name=$_.SystemName
$free_space=$_.FreeSpace
$free_space_megs=$_.FreeSpaceMegs
$drive_letter=$_.deviceid
write-host "driver letter is: "
write-host $drive_letter
# find files written to within 1 day
#if ($drive_letter -eq 'E:')
#{
# write-host "drive letter does = E running analysis"
# $DateToCompare = (Get-date).AddDays(-1)
# $Dir = get-childitem \\$the_system_name\E$ -recurse | where {$_.lastwritetime -gt $datetocompare}
# write-host "Directory is" $Dir
# $List = | format-table
# $list | format-table name
#, lastwritetime, length
#write-host $list
#write-host $Dir
#write-host "above is the list"
#sleep 5
#}
#write-host "did it write data above of the files?"
#sleep 2
# Nigel Notes, have to put the variables into different variables otherwise for some reason
# they will print all data just for one of the fields, so trying to just display percent free space results
# in all the fields showing
Write-Host $_.SystemName $_.DeviceID $_.FileSystem "FreeSpace:" $_.FreeSpace ", Actual Size:" $_.Size, "Percentage Free" $percentage_free -foreground white -backgroundcolor magenta
if ($percentage_free -lt 3)
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_email 'Server: $the_system_name, Percentage of Free Disk Space Left is: $percentage_free PERCENT, Free Unused Space is: $free_space GIGS, Free Unused Space: $free_space_megs MEGS DETAILS:$_.SystemName Time of Discovery: $mydate ... Less than 3 percent Free ... ','$filetoprocess', '$the_system_name'"
}
elseif ($percentage_free -lt 7)
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_email 'Server: $the_system_name Percentage of Free Disk Space Left is: $percentage_free PERCENT Free Unused Space is: $free_space Gigs , Free Unused Space: $free_space_megs MEGS DETAILS: $_.SystemName Time of Discovery: $mydate ... less than 5 Percent Free ... ','$filetoprocess','$the_system_name'"
Write-Host "Sending Email.... less than 5 percent free"
}
}
# end of inner loop
}
# end of outter loop
Write-Host "COMPLETE......................"
# send an email to Nigel to let me know that it at least ran, even if no thresholds were breached
sqlcmd /S bakerx /E -d msdb /Q "exec sp_email5 'Completed AT : %DATE% %TIME%"
Nigel
Customer Analysis Tool CAT
########################################################################
# Customer Analysis Tool C.A.T.
#
# Campaigns
#
# Author: Nigel Glenwood Microsoft
# Description:
# Analyze Customer Data Quickly to Improve Resolution Times of Issues
# and Provide overall better customer service
#
# Technologies Utilized:
# .net for windows forms buttons etc...
# SQL
# SQL Server
# Powershell
# Primal Forms By Sapien
# \\transfer\transfer
##########################################################################
##########################################################################
# Initial Setup Section
# Nigel NOtes
# setup a binding source
# setup sql adapater
##########################################################################
# Nigel notes, check that powershell can run, may need to set execution policy
#get-executionpolicy
#$a = read-host "hit enter to continue"
#set-Executionpolicy remotesigned
#set-Executionpolicy unrestricted
# Nige Note: load assemblies so we can utilize bindingsource, windows forms etc...
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
$bindingSource1 = new-object System.Windows.Forms.BindingSource
$bindingSource2 = new-object System.Windows.Forms.BindingSource
$dataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
# Nigel Notes
# setup connection String to SQL create datatable to house data then place the data into datagrid gui
#testing
#$connString = "Server=aittiis173;Database=master;Integrated Security=SSPI;"
#Production
$connString = "Server=by2mtza407;Database=adcenter_campaign_common;Integrated Security=SSPI;Connect Timeout=6000000"
#Generated Form Function
function GenerateForm {
########################################################################
# Generated By: niglen
########################################################################
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
#
# progress bar is just a GUI status bar basically that you can increment
# pogramatically to give illusion that system is working good if query may take a long time
#
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$button1 = New-Object System.Windows.Forms.Button
$dataGrid1 = New-Object System.Windows.Forms.DataGrid
$dataGrid2 = New-Object System.Windows.Forms.DataGrid
$textBoxaccountID = New-Object System.Windows.Forms.TextBox
$label1 = New-Object System.Windows.Forms.Label
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
####################################################################################################################################################
# EVENTS
####################################################################################################################################################
#----------------------------------------------
#Nigel Custom Code
#----------------------------------------------
$button1_OnClick=
{
$progressBar1.PerformStep()
# build query
$mydata = $textBoxaccountID.text
# use x0940170 with p4 and it brings back data good as a test
$query = "
use AdCenter_Campaign_p4
declare @the_campaign int
set @the_campaign = 20431270
select top 200 * from campaign
join status on campaign.PauseStatusId = status.statusid
where accountid in (select accountid from account where AccountNumber = '$mydata')
and lifecyclestatusId = 121 and PauseStatusId = 125"
# above line is end of the query
#select top 10 AccountId, AccountNumber, AccountName, FinancialStatusId, modifiedbyuserid, modifiedDTim, [Status].Statusname, [Status].statusdesc from
#account join status on Account.FinancialStatusId = [Status].StatusId where AccountID = '$mydata' order by ModifiedDTim DESC"
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$progressBar1.PerformStep()
#below for testing
#$query = "select * from sys.objects"
# run query and place into datatable
$dataAdapter.SelectCommand = new-object System.Data.SqlClient.SqlCommand ($query,$connString)
# Set the timeout to 999 Seconds
$dataAdapter.SelectCommand.CommandTimeout=999
$commandBuilder = new-object System.Data.SqlClient.SqlCommandBuilder $dataAdapter
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$dt = New-Object System.Data.DataTable
[void]$dataAdapter.fill($dt)
$progressBar1.PerformStep()
$bindingSource1.DataSource = $dt
$progressBar1.PerformStep()
# $dataGrid1.AutoResizeColumns([System.Windows.Forms.DataGridViewAutoSizeColumnsMode]::AllCellsExceptHeader)
$progressBar1.PerformStep()
# Place data into the Datagrid on the Form.
$dataGrid1.DataSource = $bindingSource1
#write-host $dt | format-table | out-string
# Query #2 Test NIGEL
$query = "select top 100 * from account
where AccountNumber = '$mydata'"
# run query and place into datatable
$dataAdapter.SelectCommand = new-object System.Data.SqlClient.SqlCommand ($query,$connString)
# Set the timeout to 999 Seconds
$dataAdapter.SelectCommand.CommandTimeout=999
$commandBuilder = new-object System.Data.SqlClient.SqlCommandBuilder $dataAdapter
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$dt2 = New-Object System.Data.DataTable
[void]$dataAdapter.fill($dt2)
$progressBar1.PerformStep()
$bindingSource2.DataSource = $dt2
$progressBar1.PerformStep()
# Place data into the Datagrid on the Form.
$dataGrid2.DataSource = $bindingSource2
$results = $dt.select() | Out-String
# write it out to console, can easily write out to a file if you want.
write-host $results
$results.Count
#added code
foreach ($objItem in $results) {
write-host writing value
write-host $objItem.$_
}
$progressBar1.PerformStep()
$progressbar1.Value=0
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.BackgroundImageLayout = 0
$form1.Text = "Proactive Advertising Monitoring P.A.M."
$form1.Name = "form1"
$form1.BackgroundImage = [System.Drawing.Image]::FromFile('.\background.png')
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1400
$System_Drawing_Size.Height = 784
$form1.ClientSize = $System_Drawing_Size
$progressBar1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 243
$System_Drawing_Size.Height = 23
$progressBar1.Size = $System_Drawing_Size
$progressBar1.TabIndex = 5
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 922
$System_Drawing_Point.Y = 117
$progressBar1.Location = $System_Drawing_Point
$progressBar1.Name = "progressBar1"
$progressBar1.Step = 10
#$progressBar1.PerformStep()
$form1.Controls.Add($progressBar1)
$button1.TabIndex = 4
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 41
$System_Drawing_Size.Height = 39
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.BackgroundImage = [System.Drawing.Image]::FromFile('.\Search.PNG')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 323
$System_Drawing_Point.Y = 109
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.BackgroundImageLayout = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 800
$System_Drawing_Size.Height = 80
$dataGrid1.Size = $System_Drawing_Size
$dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid1.Name = "dataGrid1"
$dataGrid1.DataMember = ""
$dataGrid1.TabIndex = 3
#$dataGrid1.BackColor = [System.Drawing.Color]::FromArgb(255,191,205,219)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 161
$dataGrid1.Location = $System_Drawing_Point
$dataGrid1.BackgroundColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$form1.Controls.Add($dataGrid1)
# new code nigel
# this just adds all the GUI to the form
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 800
$System_Drawing_Size.Height = 120
$dataGrid2.Size = $System_Drawing_Size
$dataGrid2.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid2.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid2.Name = "dataGrid2"
$dataGrid2.DataMember = ""
$dataGrid2.TabIndex = 3
#$dataGrid2.BackColor = [System.Drawing.Color]::FromArgb(212,131,215,200)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 261
$dataGrid2.Location = $System_Drawing_Point
$dataGrid2.BackgroundColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$form1.Controls.Add($dataGrid2)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 137
$System_Drawing_Size.Height = 30
$textBoxaccountID.Size = $System_Drawing_Size
$textBoxaccountID.DataBindings.DefaultDataSourceUpdateMode = 0
$textBoxaccountID.Name = "textBoxaccountID"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 110
$System_Drawing_Point.Y = 121
$textBoxaccountID.Location = $System_Drawing_Point
$textBoxaccountID.TabIndex = 2
$textBoxaccountID.text = 'x0940170'
$form1.Controls.Add($textBoxaccountID)
$label1.TabIndex = 1
$label1.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 120
$System_Drawing_Size.Height = 33
$label1.Size = $System_Drawing_Size
$label1.FlatStyle = 1
$label1.Text = "Enter Account Number:"
$label1.Font = New-Object System.Drawing.Font("Georgia",9.75,0,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 115
$label1.Location = $System_Drawing_Point
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Name = "label1"
$form1.Controls.Add($label1)
$pictureBox1.TabIndex = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1179
$System_Drawing_Size.Height = 103
$pictureBox1.Size = $System_Drawing_Size
$pictureBox1.ImageLocation = ".\Microsoft Advertising.png"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = -2
$System_Drawing_Point.Y = 0
$pictureBox1.Location = $System_Drawing_Point
$pictureBox1.InitialImage = [System.Drawing.Image]::FromFile('.\Microsoft Advertising.png')
$pictureBox1.TabStop = $False
$pictureBox1.Name = "pictureBox1"
$pictureBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Controls.Add($pictureBox1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function to generate the form nigel
GenerateForm
# END OF CODE
How to use:
1) Open the attached file, and copy the text
2) In the PHX TS server, normally tk2tscorp.phx.gbl open notepad
3) Paste the code
4) Save as .ps1 (note the location, should be in your documents)
5) Right click on the document, and state run with powershell
a. Or open cmd prompt, navigate to the folder
b. Powerhsell
c. .\mypowershellscript.ps1
6) The cmd script will allow you to see all the errors if the script is really hosed
7) Adjust the sql and connection string as needed.
# Customer Analysis Tool C.A.T.
#
# Campaigns
#
# Author: Nigel Glenwood Microsoft
# Description:
# Analyze Customer Data Quickly to Improve Resolution Times of Issues
# and Provide overall better customer service
#
# Technologies Utilized:
# .net for windows forms buttons etc...
# SQL
# SQL Server
# Powershell
# Primal Forms By Sapien
# \\transfer\transfer
##########################################################################
##########################################################################
# Initial Setup Section
# Nigel NOtes
# setup a binding source
# setup sql adapater
##########################################################################
# Nigel notes, check that powershell can run, may need to set execution policy
#get-executionpolicy
#$a = read-host "hit enter to continue"
#set-Executionpolicy remotesigned
#set-Executionpolicy unrestricted
# Nige Note: load assemblies so we can utilize bindingsource, windows forms etc...
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
$bindingSource1 = new-object System.Windows.Forms.BindingSource
$bindingSource2 = new-object System.Windows.Forms.BindingSource
$dataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
# Nigel Notes
# setup connection String to SQL create datatable to house data then place the data into datagrid gui
#testing
#$connString = "Server=aittiis173;Database=master;Integrated Security=SSPI;"
#Production
$connString = "Server=by2mtza407;Database=adcenter_campaign_common;Integrated Security=SSPI;Connect Timeout=6000000"
#Generated Form Function
function GenerateForm {
########################################################################
# Generated By: niglen
########################################################################
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
#
# progress bar is just a GUI status bar basically that you can increment
# pogramatically to give illusion that system is working good if query may take a long time
#
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$button1 = New-Object System.Windows.Forms.Button
$dataGrid1 = New-Object System.Windows.Forms.DataGrid
$dataGrid2 = New-Object System.Windows.Forms.DataGrid
$textBoxaccountID = New-Object System.Windows.Forms.TextBox
$label1 = New-Object System.Windows.Forms.Label
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
####################################################################################################################################################
# EVENTS
####################################################################################################################################################
#----------------------------------------------
#Nigel Custom Code
#----------------------------------------------
$button1_OnClick=
{
$progressBar1.PerformStep()
# build query
$mydata = $textBoxaccountID.text
# use x0940170 with p4 and it brings back data good as a test
$query = "
use AdCenter_Campaign_p4
declare @the_campaign int
set @the_campaign = 20431270
select top 200 * from campaign
join status on campaign.PauseStatusId = status.statusid
where accountid in (select accountid from account where AccountNumber = '$mydata')
and lifecyclestatusId = 121 and PauseStatusId = 125"
# above line is end of the query
#select top 10 AccountId, AccountNumber, AccountName, FinancialStatusId, modifiedbyuserid, modifiedDTim, [Status].Statusname, [Status].statusdesc from
#account join status on Account.FinancialStatusId = [Status].StatusId where AccountID = '$mydata' order by ModifiedDTim DESC"
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$progressBar1.PerformStep()
#below for testing
#$query = "select * from sys.objects"
# run query and place into datatable
$dataAdapter.SelectCommand = new-object System.Data.SqlClient.SqlCommand ($query,$connString)
# Set the timeout to 999 Seconds
$dataAdapter.SelectCommand.CommandTimeout=999
$commandBuilder = new-object System.Data.SqlClient.SqlCommandBuilder $dataAdapter
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$dt = New-Object System.Data.DataTable
[void]$dataAdapter.fill($dt)
$progressBar1.PerformStep()
$bindingSource1.DataSource = $dt
$progressBar1.PerformStep()
# $dataGrid1.AutoResizeColumns([System.Windows.Forms.DataGridViewAutoSizeColumnsMode]::AllCellsExceptHeader)
$progressBar1.PerformStep()
# Place data into the Datagrid on the Form.
$dataGrid1.DataSource = $bindingSource1
#write-host $dt | format-table | out-string
# Query #2 Test NIGEL
$query = "select top 100 * from account
where AccountNumber = '$mydata'"
# run query and place into datatable
$dataAdapter.SelectCommand = new-object System.Data.SqlClient.SqlCommand ($query,$connString)
# Set the timeout to 999 Seconds
$dataAdapter.SelectCommand.CommandTimeout=999
$commandBuilder = new-object System.Data.SqlClient.SqlCommandBuilder $dataAdapter
$progressBar1.PerformStep()
$progressBar1.PerformStep()
$dt2 = New-Object System.Data.DataTable
[void]$dataAdapter.fill($dt2)
$progressBar1.PerformStep()
$bindingSource2.DataSource = $dt2
$progressBar1.PerformStep()
# Place data into the Datagrid on the Form.
$dataGrid2.DataSource = $bindingSource2
$results = $dt.select() | Out-String
# write it out to console, can easily write out to a file if you want.
write-host $results
$results.Count
#added code
foreach ($objItem in $results) {
write-host writing value
write-host $objItem.$_
}
$progressBar1.PerformStep()
$progressbar1.Value=0
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.BackgroundImageLayout = 0
$form1.Text = "Proactive Advertising Monitoring P.A.M."
$form1.Name = "form1"
$form1.BackgroundImage = [System.Drawing.Image]::FromFile('.\background.png')
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1400
$System_Drawing_Size.Height = 784
$form1.ClientSize = $System_Drawing_Size
$progressBar1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 243
$System_Drawing_Size.Height = 23
$progressBar1.Size = $System_Drawing_Size
$progressBar1.TabIndex = 5
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 922
$System_Drawing_Point.Y = 117
$progressBar1.Location = $System_Drawing_Point
$progressBar1.Name = "progressBar1"
$progressBar1.Step = 10
#$progressBar1.PerformStep()
$form1.Controls.Add($progressBar1)
$button1.TabIndex = 4
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 41
$System_Drawing_Size.Height = 39
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.BackgroundImage = [System.Drawing.Image]::FromFile('.\Search.PNG')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 323
$System_Drawing_Point.Y = 109
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.BackgroundImageLayout = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 800
$System_Drawing_Size.Height = 80
$dataGrid1.Size = $System_Drawing_Size
$dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid1.Name = "dataGrid1"
$dataGrid1.DataMember = ""
$dataGrid1.TabIndex = 3
#$dataGrid1.BackColor = [System.Drawing.Color]::FromArgb(255,191,205,219)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 161
$dataGrid1.Location = $System_Drawing_Point
$dataGrid1.BackgroundColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$form1.Controls.Add($dataGrid1)
# new code nigel
# this just adds all the GUI to the form
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 800
$System_Drawing_Size.Height = 120
$dataGrid2.Size = $System_Drawing_Size
$dataGrid2.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid2.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid2.Name = "dataGrid2"
$dataGrid2.DataMember = ""
$dataGrid2.TabIndex = 3
#$dataGrid2.BackColor = [System.Drawing.Color]::FromArgb(212,131,215,200)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 261
$dataGrid2.Location = $System_Drawing_Point
$dataGrid2.BackgroundColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$form1.Controls.Add($dataGrid2)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 137
$System_Drawing_Size.Height = 30
$textBoxaccountID.Size = $System_Drawing_Size
$textBoxaccountID.DataBindings.DefaultDataSourceUpdateMode = 0
$textBoxaccountID.Name = "textBoxaccountID"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 110
$System_Drawing_Point.Y = 121
$textBoxaccountID.Location = $System_Drawing_Point
$textBoxaccountID.TabIndex = 2
$textBoxaccountID.text = 'x0940170'
$form1.Controls.Add($textBoxaccountID)
$label1.TabIndex = 1
$label1.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 120
$System_Drawing_Size.Height = 33
$label1.Size = $System_Drawing_Size
$label1.FlatStyle = 1
$label1.Text = "Enter Account Number:"
$label1.Font = New-Object System.Drawing.Font("Georgia",9.75,0,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 115
$label1.Location = $System_Drawing_Point
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Name = "label1"
$form1.Controls.Add($label1)
$pictureBox1.TabIndex = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1179
$System_Drawing_Size.Height = 103
$pictureBox1.Size = $System_Drawing_Size
$pictureBox1.ImageLocation = ".\Microsoft Advertising.png"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = -2
$System_Drawing_Point.Y = 0
$pictureBox1.Location = $System_Drawing_Point
$pictureBox1.InitialImage = [System.Drawing.Image]::FromFile('.\Microsoft Advertising.png')
$pictureBox1.TabStop = $False
$pictureBox1.Name = "pictureBox1"
$pictureBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Controls.Add($pictureBox1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function to generate the form nigel
GenerateForm
# END OF CODE
How to use:
1) Open the attached file, and copy the text
2) In the PHX TS server, normally tk2tscorp.phx.gbl open notepad
3) Paste the code
4) Save as .ps1 (note the location, should be in your documents)
5) Right click on the document, and state run with powershell
a. Or open cmd prompt, navigate to the folder
b. Powerhsell
c. .\mypowershellscript.ps1
6) The cmd script will allow you to see all the errors if the script is really hosed
7) Adjust the sql and connection string as needed.
Subscribe to:
Comments (Atom)