Added existing scripts

This commit is contained in:
2022-09-13 12:38:57 -05:00
parent 251dbfb0eb
commit 845bc9d7a3
38 changed files with 1340 additions and 0 deletions

22
powershell/AWE_PID.ps1 Normal file
View File

@ -0,0 +1,22 @@
$AMLHead = '</AMTASKHEAD>
<AMFUNCTION NAME="Main" ACCESS="private" RETURNTYPE="variable">'
# Set Variable to replace start of AWE with Start of AWE and Capture PID flow
#Change "<AMFILESYSTEM ACTIVITY" Line to a file location on your server
$AMLtask = '</AMTASKHEAD>
<AMFUNCTION NAME="Main" ACCESS="private" RETURNTYPE="variable">
<AMVARIABLE NAME="ProcessPID" VALUE="" PRIVATE="YES" />
<AMSCRIPT>Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Sub Main
ProcessPID = GetCurrentProcessId()
End Sub</AMSCRIPT>
<AMFILESYSTEM ACTIVITY="write_file" FILE="C:\Temp\PID%ProcessPID%.log">%Now()%, %GetTaskName()% --- %AWE_TASK_NAME%, PID: %ProcessPID%</AMFILESYSTEM>
'
Get-ChildItem 'C:\Users\jbranan\Desktop\test\*.aml' -Recurse | ForEach {
(Get-Content $_ | ForEach { $_ -replace $AMLHead, $AMLtask }) |
Set-Content $_
}

View File

@ -0,0 +1,7 @@
$startTimeLimit = (get-date) - (new-timespan -minutes 2)
$processes_to_kill = get-process |
where {$_.StartTime -lt $startTimeLimit -and ($_.path -like "GSAWE.exe") }
if ($processes_to_kill -ne $null)
{
$processes_to_kill | foreach { $_.Kill() }
}

View File

@ -0,0 +1,72 @@
#List of hostnames
$hostnames=@("CELES0272016","TERRA0372016");
#EFT Admin Credentials
$EFTAdminUsername = "a";
$EFTAdminPassword = "a";
$EFTAdminPort = 1100;
#EFT Com Object
$script:EftServer = $null
#List of hostnames that can be administrated at the same time
$output=@();
#$output=$hostnames# Debug, uncomment this line and set $lockfailure to "true".
#String representing lock failure.
$lockfailure=$false;
#Output <DATE> <TIME> <UTC Offset>
Function getdate
{
Get-Date -Format "MM/dd/yyyy HH:mm:ss K "
}
$currenttime = getdate
#Path to log file
$Logfile = "\\IV-S2019B-3\config\adminlock.log"
#Function to accept string input and append to $Logfile
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
#$EFTnodename = ''
#Set-Variable -Name "EFTnodename" ($EFT_CONTEXT.GetVariable("SERVER.NODE_NAME"))
#$logstring = $EFTnodename
#LogWrite $logstring
#Main, Loop through hostnames in $hostname array and attempt connection via com.Successful connections are counted by $flag.
#If a COM connection is successful to more than one server in the array, the $lockfailure variable is set to true.
$flag=0;
$output=''
for ($i=0;$i -le $hostnames.count-1; $i++){
foreach ($EFTAdminHostname in $hostnames[$i]){
$script:EftServer = new-object -ComObject "SFTPCOMInterface.CIServer"
try {
$script:EftServer.ConnectEx($EFTAdminHostname, $EFTAdminPort, $EFTAdminAuthType, $EFTAdminUsername, $EFTAdminPassword)
$flag++;
$output=$output +' '+ $EFTAdminHostname
$script:EftServer.close();
}
catch [System.Runtime.InteropServices.COMException] {
}
}
if ($flag -gt 1){
$lockfailure=$true;
}
}
if ($lockfailure -eq $true){
$lockstatus = 'AdminsLock unstable.';
$lockstatusdetail = " Multiple servers can be accessed:"+' '+$output;
$logstring= $currenttime + $lockstatus + $lockstatusdetail+" LockFailure:Yes" +" Flag:"+ $flag #+ " ERNode:" + $EFT_CONTEXT.GetVariable("SERVER.NODE_NAME")
Write-Host $currenttime $lockstatus $lockstatusdetail
LogWrite $logstring
}
else{
$lockstatus = 'AdminsLock stable.'
$lockstatusdetail = " Connected to:"+' '+$output;
$logstring= $currenttime + $lockstatus +$lockstatusdetail + " LockFailure:No" +" Flag:"+ $flag #+ " ERNode:" + $EFT_CONTEXT.GetVariable("SERVER.NODE_NAME")
Write-Host $currenttime $lockstatus + $output
LogWrite $logstring
}

View File

@ -0,0 +1,5 @@
$clients_to_check = @('a', 'b')
foreach($client in $clients_to_check){
Start-Process https://$client.arcusapp.globalscape.com
}

View File

@ -0,0 +1,140 @@
# (c) Robert Carter
# Hide PowerShell Console
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
$consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 0)
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '528,70'
$Form.text = "Dummy File Creator v1.0"
$Form.TopMost = $false
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{Create-Dummy}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})
$PathBx = New-Object system.Windows.Forms.TextBox
$PathBx.multiline = $false
$PathBx.width = 172
$PathBx.height = 20
$PathBx.location = New-Object System.Drawing.Point(9,35)
$PathBx.Font = 'Microsoft Sans Serif,10'
$PathBx.Text = $Env:userprofile + "\Desktop"
$CreateBt = New-Object system.Windows.Forms.Button
$CreateBt.text = "Create"
$CreateBt.width = 60
$CreateBt.height = 30
$CreateBt.location = New-Object System.Drawing.Point(449,19)
$CreateBt.Font = 'Microsoft Sans Serif,10,style=Bold'
$SizeBx = New-Object system.Windows.Forms.TextBox
$SizeBx.multiline = $false
$SizeBx.width = 51
$SizeBx.height = 20
$SizeBx.location = New-Object System.Drawing.Point(321,35)
$SizeBx.Font = 'Microsoft Sans Serif,10'
$SizeBx.Text = '20'
$QuantityBx = New-Object system.Windows.Forms.TextBox
$QuantityBx.multiline = $false
$QuantityBx.width = 36
$QuantityBx.height = 20
$QuantityBx.location = New-Object System.Drawing.Point(383,35)
$QuantityBx.Font = 'Microsoft Sans Serif,10'
$QuantityBx.Text = '1'
$PathLb = New-Object system.Windows.Forms.Label
$PathLb.text = "Path to file:"
$PathLb.AutoSize = $true
$PathLb.width = 25
$PathLb.height = 10
$PathLb.location = New-Object System.Drawing.Point(9,12)
$PathLb.Font = 'Microsoft Sans Serif,10'
$SizeLb = New-Object system.Windows.Forms.Label
$SizeLb.text = "Size MB:"
$SizeLb.AutoSize = $true
$SizeLb.width = 25
$SizeLb.height = 10
$SizeLb.location = New-Object System.Drawing.Point(321,12)
$SizeLb.Font = 'Microsoft Sans Serif,10'
$QuantityLb = New-Object system.Windows.Forms.Label
$QuantityLb.text = "Quantity:"
$QuantityLb.AutoSize = $true
$QuantityLb.width = 25
$QuantityLb.height = 10
$QuantityLb.location = New-Object System.Drawing.Point(383,11)
$QuantityLb.Font = 'Microsoft Sans Serif,10'
$BrowseBt = New-Object system.Windows.Forms.Button
$BrowseBt.text = "..."
$BrowseBt.width = 27
$BrowseBt.height = 24
$BrowseBt.location = New-Object System.Drawing.Point(195,35)
$BrowseBt.Font = 'Microsoft Sans Serif,10'
$BrowseBt.Add_Click({$browse.ShowDialog();$PathBx.Text = $Browse.SelectedPath })
$FileNameBx = New-Object system.Windows.Forms.TextBox
$FileNameBx.multiline = $false
$FileNameBx.width = 75
$FileNameBx.height = 20
$FileNameBx.location = New-Object System.Drawing.Point(233,35)
$FileNameBx.Font = 'Microsoft Sans Serif,10'
$FileNameBx.Text = "dummy.txt"
$FileNameLb = New-Object system.Windows.Forms.Label
$FileNameLb.text = "FileName:"
$FileNameLb.AutoSize = $true
$FileNameLb.width = 25
$FileNameLb.height = 10
$FileNameLb.location = New-Object System.Drawing.Point(233,13)
$FileNameLb.Font = 'Microsoft Sans Serif,10'
$Browse = new-object system.windows.Forms.FolderBrowserDialog
$Browse.RootFolder = [System.Environment+SpecialFolder]'MyComputer'
$Browse.ShowNewFolderButton = $true
$Browse.selectedPath = "C:\"
$Browse.Description = "Choose a directory:"
$Form.controls.AddRange(@($PathBx,$CreateBt,$SizeBx,$QuantityBx,$PathLb,$SizeLb,$QuantityLb,$BrowseBt,$FileNameBx,$FileNameLb))
$CreateBt.Add_Click({Create-Dummy})
Function Create-Dummy {
$exten = $null
If ($FileNameBx.Text.Contains('.'))
{
$exten = '.' + $FileNameBx.Text.Split('.')[1]
}
fsutil file createnew ($PathBx.Text + '\' + $FileNameBx.Text) (($SizeBx.Text -as [INT]) * 1048576)
For($j = ($QuantityBx.Text -as [INT]); $j -gt 1; $j--)
{
fsutil file createnew ($PathBx.Text + '\' + $FileNameBx.Text.Split('.')[0] + $j + $exten) (($SizeBx.Text -as [INT]) * 1048576)
}
}
#Show form
$Form.Topmost = $True
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

View File

@ -0,0 +1,15 @@
$serverIp = "localhost"
$serverPort = 1100
$serverUsername = "a"
$serverPassword = "a"
$EFTServer = New-Object -COM "SFTPCOMInterface.CIServer"
$EFTServer.ConnectEX($serverIP, $serverPort, 0, $serverUsername, $serverPassword)
$EFTServer.Sites().Count()
for($j = 0; $j -lt $EFTServer.Sites().Count(); $j++)
{
Write-Host "Site Index - Site Name - Site GUID"
$a = $j + 1
Write-Host $a - $EFTServer.Sites().Item($j).Name - $EFTServer.Sites().Item($j).GUID
}

View File

@ -0,0 +1,62 @@
<#
.SYNOPSIS
Watchdog Script that will send a notification if a folder gets too full.
.DESCRIPTION
The Script will Send E-Mail for folders with files over a specified amount. This ammount is controlled by the $filelimit variable.
The script supports searching multiple directories; The folders will need to be inserted into the array $folderlist.
Change the SMTP server variable block to work in your environment.
.AUTHOR
Jonathan Branan <jbranan@globalscape.com>
.WARRANTY
This script is provided with no warranty and is not garunteed to work. Globalscape, Helpsystems or the Author assume NO responsibility for
the outcome of running the script.
#>
# List of folders to parse. Delimit by commas, make sure the paths are in double quotes.
$folderlist = @("C:\InetPub\EFTRoot\MySite")
# Minimum of files in a directory before the notfication is sent.
$filelimit = 100
#SMTP Server Block # CHANGE ME
$smtpserver = "mail.globalscape.com"
$from = "watchdog@server.com"
$to = "jbranan@globalscape.com"
$subject = "Folder Watch Dog"
$port = 25
$data = ForEach($Folder in $folderlist){
Get-ChildItem $Folder -Directory -Recurse|
ForEach-Object{
[pscustomobject]@{
FullName = $_.Fullname.ToLower()
FileCount = $_.GetFiles().Count
# Filters
} | Where-Object {$_.FileCount -ge $filelimit} | Where-Object {$_.FullName -cnotlike '*archive*'}
}
}
# Building a table
$tbl = New-Object System.Data.DataTable "FileCount"
$col1 = New-Object System.Data.DataColumn FullName
$col2 = New-Object System.Data.DataColumn FileCount
$tbl.Columns.Add($col1)
$tbl.Columns.Add($col2)
ForEach($array in $data){
$row = $tbl.NewRow()
$row.FullName = $array.FullName
$row.FileCount = $array.FileCount
$tbl.Rows.Add($row)
}
# Formatting the table so we can email it
$html = $tbl | Select-Object Fullname, Filecount | ConvertTo-Html -Property FullName, FileCount -Title 'Folders reaching the file limit'
$body = "Hi there,<br />Folders reaching the limit:<br /><br />" + $html
#Send the email
Send-MailMessage -smtpserver $smtpserver -Port $port -from $from -to $to -subject $subject -body $body -bodyashtml
#You can comment out Send-MailMessage and uncomment out the next line if you wish to debug filters
#$tbl | Select-Object Fullname, Filecount

View File

@ -0,0 +1,62 @@
<#
.SYNOPSIS
Watchdog Script that will send a notification if a folder gets too full.
.DESCRIPTION
The Script will Send E-Mail for folders with files over a specified amount. This ammount is controlled by the $filelimit variable.
The script supports searching multiple directories; The folders will need to be inserted into the array $folderlist.
Change the SMTP server variable block to work in your environment.
.AUTHOR
Jonathan Branan <jbranan@globalscape.com>
.WARRANTY
This script is provided with no warranty and is not garunteed to work. Globalscape, Helpsystems or the Author assume NO responsibility for
the outcome of running the script.
#>
# List of folders to parse. Delimit by commas, make sure the paths are in double quotes.
$folderlist = @("\\file.core.windows.net\gsbdata\InetPub\EFTRoot\MySite\Usr\FTPISO\Archive")
# Minimum of files in a directory before the notfication is sent.
$filelimit = 2
#SMTP Server Block # CHANGE ME
$smtpserver = "mail.globalscape.com"
$from = "watchdog@server.com"
$to = "jonathan.branan@helpsystems.com"
$subject = "Folder Watch Dog"
$port = 25
$data = ForEach($Folder in $folderlist){
Get-ChildItem $Folder -Directory -Recurse|
ForEach-Object{
[pscustomobject]@{
FullName = $_.Fullname.ToLower()
FileCount = $_.GetFiles().Count
# Filters
} | Where-Object {$_.FileCount -ge $filelimit}
}
}
# Building a table
$tbl = New-Object System.Data.DataTable "FileCount"
$col1 = New-Object System.Data.DataColumn FullName
$col2 = New-Object System.Data.DataColumn FileCount
$tbl.Columns.Add($col1)
$tbl.Columns.Add($col2)
ForEach($array in $data){
$row = $tbl.NewRow()
$row.FullName = $array.FullName
$row.FileCount = $array.FileCount
$tbl.Rows.Add($row)
}
# Formatting the table so we can email it
$html = $tbl | Select-Object Fullname, Filecount | ConvertTo-Html -Property FullName, FileCount -Title 'Folders reaching the file limit'
$body = "Hi there,<br />Folders reaching the limit:<br /><br />" + $html
#Send the email
Send-MailMessage -smtpserver $smtpserver -Port $port -from $from -to $to -subject $subject -body $body -bodyashtml
#You can comment out Send-MailMessage and uncomment out the next line if you wish to debug filters
#$tbl | Select-Object Fullname, Filecount

View File

@ -0,0 +1,7 @@
Get-HotFix |
Where {
$_.InstalledOn -gt "07/01/2019" -AND $_.InstalledOn -lt "09/01/2019" } |
sort InstalledOn | Out-File $HOME\desktop\installedupdates.txt

View File

@ -0,0 +1,26 @@
$server_ip = "192.168.102.28"
$server_port = 1100
$admin_username = "insight"
$admin_password = "a"
$site_name = "GS"
$server = New-Object -ComObject SFTPCOMInterface.CIServer
$server.connect($server_ip,$server_port,$admin_username,$admin_password)
$site_list = $server.Sites()
for ($i = 0; $i -lt $site_list.Count(); $i++) {
$site = $site_list.Item($i)
if ($site.Name -eq $site_name) {
break
}
}
$date = "11/1/2006"
$date = [datetime] $date
$username = Read-Host "Which user do you want to remove a key from?"
$settings = $site.GetUserSettings($username)
$settings.setExpirationDate($date, 0)

View File

@ -0,0 +1,63 @@
<#
.SYNOPSIS
Use EFT's COM interface to configure ARM settings for auditing and reporting.
.DESCRIPTION
Use EFT's COM interface to retrieve ARM settings
.PARAMETER serverName
.PARAMETER eftAdminPort
.PARAMETER authMethod
.PARAMETER eftAdminName
.PARAMETER eftAdminPassword
#>
param(
[Parameter(Mandatory=$False)][string]$serverName = "localhost",
[Parameter(Mandatory=$False)][int]$eftAdminPort = 1100,
[Parameter(Mandatory=$False)][int]$authMethod = 1,
[Parameter(Mandatory=$False)][string]$eftAdminName = "",
[Parameter(Mandatory=$False)][string]$eftAdminPassword = ""
)
#------------------------------------------------------------
# login as admin
#------------------------------------------------------------
try {
$oServer = New-Object -ComObject 'SFTPComInterface.CIServer'
$oServer.ConnectEx( $serverName, $eftAdminPort, $authMethod, $eftAdminName, $eftAdminPassword );
Write-Host "connected"
}
catch {
$errorMessage = $_.Exception.Message;
Write-Host "failed to connect to server ${serverName}: ${errorMessage}"
Exit;
}
#------------------------------------------------------------
# get ARM settings
#------------------------------------------------------------
Write-Output ("ARMServerName: {0}" -f $oServer.ARMServerName)
Write-Output ("ARMDatabaseName: {0}" -f $oServer.ARMDatabaseName)
Write-Output ("ARMUserName: {0}" -f $oServer.ARMUserName)
Write-Output ("ARMPassword: {0}" -f $oServer.ARMPassword)
Write-Output ("ARMDatabaseType: {0}" -f $oServer.ARMDatabaseType)
Write-Output ("ARMAuthenticationType: {0}" -f $oServer.ARMAuthenticationType)
#------------------------------------------------------------
# close resources
#------------------------------------------------------------
$oServer.Close()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($oServer) | out-null
Remove-Variable oServer

BIN
powershell/eft_cli.ps1 Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
Get-ChildItem -path "\\file.core.windows.net\gsbdata\" -Recurse -Force | Export-Csv D:\siteroot.csv

11
powershell/mail.ps1 Normal file
View File

@ -0,0 +1,11 @@
$smtpserver = "mail.globalscape.com"
$from = "watchdog@server.com"
$to = "jonathan.branan@helpsystems.com"
$subject = "Folder Watch Dog"
$port = 25
$body = "Hi there,<br />Folders reaching the limit:<br /><br />"
#Send the email
Send-MailMessage -smtpserver $smtpserver -Port $port -from $from -to $to -subject $subject -body $body -bodyashtml

View File

@ -0,0 +1,115 @@
<#
.SYNOPSIS
Use EFT's COM interface to configure ARM settings for auditing and reporting.
.DESCRIPTION
Use EFT's COM interface to check status of ARM and reconnect if needed
.PARAMETER serverName
.PARAMETER eftAdminPort
.PARAMETER authMethod
.PARAMETER eftAdminName
.PARAMETER eftAdminPassword
#>
param(
[Parameter(Mandatory=$False)][string]$serverName = "localhost",
[Parameter(Mandatory=$False)][int]$eftAdminPort = 1100,
[Parameter(Mandatory=$False)][int]$authMethod = 1,
[Parameter(Mandatory=$False)][string]$eftAdminName = "",
[Parameter(Mandatory=$False)][string]$eftAdminPassword = ""
)
#------------------------------------------------------------
# Setup logging to a file
#------------------------------------------------------------
#Output <DATE> <TIME> <UTC Offset>
Function getdate
{
Get-Date -Format "MM/dd/yyyy HH:mm:ss K "
}
$currenttime = getdate
$EFT_CONTEXT.SetVariable("failure", "false")
$EFT_CONTEXT.SetVariable("status", "")
#Path to log file
$Logfile = "D:\ARM-Connection.log"
#Function to accept string input and append to $Logfile
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
#------------------------------------------------------------
# login as admin
#------------------------------------------------------------
try {
$oServer = New-Object -ComObject 'SFTPComInterface.CIServer'
$oServer.ConnectEx( $serverName, $eftAdminPort, $authMethod, $eftAdminName, $eftAdminPassword );
Write-Host "connected"
}
catch {
$errorMessage = $_.Exception.Message;
Write-Host "failed to connect to server ${serverName}: ${errorMessage}"
Exit;
}
write-host $oServer.ARMConnectionStatus
#------------------------------------------------------------
# get ARM settings
#------------------------------------------------------------
#Write-Output ("ARMServerName: {0}" -f $oServer.ARMServerName)
if ($oServer.ARMConnectionStatus)
{
$logstring= $currenttime + 'ARM Is Connected.'
LogWrite $logstring
}
else
{
$logstring= $currenttime + 'ARM Is Not Connected. Testing connection to the database...'
LogWrite $logstring
$EFT_CONTEXT.SetVariable("failure", "true")
if ($oServer.ARMTestConnection())
{
Write-Output ('ARM Test Connection Succeeded. Attempting to reconnect ARM...')
$logstring= $currenttime + 'ARM Test Connection Succeeded.'
LogWrite $logstring
if ($oServer.ARMReconnect())
{
Write-Output 'ARM connection test succeeded.'
$logstring= $currenttime + 'Reconnected the disconnected ARM database'
LogWrite $logstring
$EFT_CONTEXT.SetVariable("status", "Reconnected the disconnected ARM database")
}
else
{
write-output 'Failed To Reconnect ARM.'
$logstring= $currenttime + 'Failed To Reconnect ARM.'
LogWrite $logstring
$EFT_CONTEXT.SetVariable("status", "Failed To Reconnect ARM.")
}
}
else
{
Write-Output ('ARM Test Connection Failed.')
$logstring=$currenttime + 'ARM Test Connection Failed.'
LogWrite $logstring
$EFT_CONTEXT.SetVariable("status", "ARM Test Connection Failed.")
}
}
#$oServer.ARMReconnect()
#------------------------------------------------------------
# close resources
#------------------------------------------------------------
$oServer.Close()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($oServer) | out-null
Remove-Variable oServer

View File

@ -0,0 +1,76 @@
function Reset-Log
{
#function checks to see if file in question is larger than the paramater specified if it is it will roll a log and delete the oldes log if there are more than x logs.
param([string]$fileName, [int64]$filesize = 1mb , [int] $logcount = 5)
$logRollStatus = $true
if(test-path $filename)
{
$file = Get-ChildItem $filename
if((($file).length) -ige $filesize) #this starts the log roll
{
$fileDir = $file.Directory
$fn = $file.name #this gets the name of the file we started with
$files = Get-ChildItem $filedir | ?{$_.name -like "$fn*"} | Sort-Object lastwritetime
$filefullname = $file.fullname #this gets the fullname of the file we started with
#$logcount +=1 #add one to the count as the base file is one more than the count
for ($i = ($files.count); $i -gt 0; $i--)
{
#[int]$fileNumber = ($f).name.Trim($file.name) #gets the current number of the file we are on
$files = Get-ChildItem $filedir | ?{$_.name -like "$fn*"} | Sort-Object lastwritetime
$operatingFile = $files | ?{($_.name).trim($fn) -eq $i}
if ($operatingfile)
{$operatingFilenumber = ($files | ?{($_.name).trim($fn) -eq $i}).name.trim($fn)}
else
{$operatingFilenumber = $null}
if(($operatingFilenumber -eq $null) -and ($i -ne 1) -and ($i -lt $logcount))
{
$operatingFilenumber = $i
$newfilename = "$filefullname.$operatingFilenumber"
$operatingFile = $files | ?{($_.name).trim($fn) -eq ($i-1)}
write-host "moving to $newfilename"
move-item ($operatingFile.FullName) -Destination $newfilename -Force
}
elseif($i -ge $logcount)
{
if($operatingFilenumber -eq $null)
{
$operatingFilenumber = $i - 1
$operatingFile = $files | ?{($_.name).trim($fn) -eq $operatingFilenumber}
}
write-host "deleting " ($operatingFile.FullName)
remove-item ($operatingFile.FullName) -Force
}
elseif($i -eq 1)
{
$operatingFilenumber = 1
$newfilename = "$filefullname.$operatingFilenumber"
write-host "moving to $newfilename"
move-item $filefullname -Destination $newfilename -Force
}
else
{
$operatingFilenumber = $i +1
$newfilename = "$filefullname.$operatingFilenumber"
$operatingFile = $files | ?{($_.name).trim($fn) -eq ($i-1)}
write-host "moving to $newfilename"
move-item ($operatingFile.FullName) -Destination $newfilename -Force
}
}
}
else
{ $logRollStatus = $false}
}
else
{
$logrollStatus = $false
}
$LogRollStatus
}
Reset-Log -fileName $logfile -filesize 1mb -logcount 5

6
powershell/restore.ps1 Normal file
View File

@ -0,0 +1,6 @@
$destinationFolder = "\\file.core.windows.net\gsbdata\InetPub\EFTRoot\gsbsup\Usr\Projects\SEG\ "
$restoredLocation = "\\file.core.windows.net\gsbdata\InetPub\EFTRoot\RestoredFiles\PubTech_20210128\ "
$exportfilelocation2 = "d:\restored.txt"
Robocopy /E /XC /XN /XO $restoredLocation $destinationFolder > $exportfilelocation2

6
powershell/robocopy.ps1 Normal file
View File

@ -0,0 +1,6 @@
$destinationFolder = "\\TERRA0372016\Users\jbranan\Desktop\share\New folder "
$restoredLocation = "\\TERRA0372016\Users\jbranan\Desktop\share\abetest "
$exportfilelocation2 = "d:\restored.txt"
Robocopy /E /XC /XN /XO $restoredLocation $destinationFolder > $exportfilelocation2

102
powershell/stake_out.ps1 Normal file
View File

@ -0,0 +1,102 @@
<#
.SYNOPSIS
Data collection using tools such Procmon, Procdump and Wireshark
.DESCRIPTION
This script enables an admnistrator to collect data on their server at times when they are unable to observe the issue live.
.DISCLAIMER
This script is provided without warranty. Globalscape/Helpsystems does not assume any liability for unintended functionality as a result of this script.
.VERSION
1.0
1.1 Added wireshark portable and set procmon to close itself. Also removed /nofilter in procmon.
.AUTHOR
Jonathan Branan jbranan@globalscape.com jonathan.branan@helpsystems.com
#>
#------------------------------------------------------------
# Main Variables
#------------------------------------------------------------
$working_drive = 'c:'
$working_directory = 'C:\Users\jbranan\Desktop\scripts\stake_out'
$total_time = 20
#------------------------------------------------------------
# Procmon related variables
#------------------------------------------------------------
$procmon_filename = 'log.pml'
#------------------------------------------------------------
# Wireshark related variables
#------------------------------------------------------------
$wireshark_filename = 'capture.pcapng'
$wireshark_drive = 'c:'
$wireshark_location = 'C:\Users\jbranan\Desktop\scripts\stake_out\WiresharkPortable'
$wireshark_filter = 'host 192.168.102.10'
$total_wireshark_time = $total_time + 15
#------------------------------------------------------------
# Procdump related variables
#------------------------------------------------------------
$take_service_dumps = $false
$take_gui_dumps = $false
$number_of_dumps = 3
$total_procdump_time = 60
$total_procdump_time_close = $total_procdump_time + 15
#------------------------------------------------------------
# Procmon blocks
#------------------------------------------------------------
Start-Job -Name procmon -ScriptBlock {
$using:working_drive
cd $using:working_directory"\procmon"
./procmon.exe /accepteula /Quiet /BackingFile $using:working_directory"\dumps\"$using:procmon_filename /Minimized /Runtime $using:total_time
}
#Start-Job -Name kill-procmon -ScriptBlock {
#sleep -Seconds $using:total_time
#
#taskkill /IM "Procmon64.exe" /F
#Stop-Job -Name procmon
#exit
#}
#------------------------------------------------------------
# Wireshark blocks
#------------------------------------------------------------
Start-Job -Name wireshark -ScriptBlock {
$using:wireshark_drive
cd $using:wireshark_location
./WiresharkPortable -k -i Ethernet0 -f "$using:wireshark_filter" -a duration:$using:total_time -w $using:working_directory"\dumps\"$using:wireshark_filename
}
Start-Job -Name kill-wireshark -ScriptBlock {
sleep -Seconds $using:total_wireshark_time
taskkill /IM "Wireshark.exe" /F
Stop-Job -Name wireshark
exit
}
#------------------------------------------------------------
# Procdump blocks
#------------------------------------------------------------
#
if ($take_service_dumps) {
Start-Job -Name procdump_EFT_service -ScriptBlock {
$using:working_drive
cd $using:working_directory"\procdump"
./procdump.exe -n $using:number_of_dumps -s $using:total_procdump_time -ma cftpstes.exe $using:working_directory"\dumps" -accepteula
timeout /T $using:total_procdump_time_close
exit
}
}
if ($take_gui_dumps) {
Start-Job -Name procdump_gui_service -ScriptBlock {
$using:working_drive
cd $using:working_directory"\procdump"
./procdump.exe -n $using:number_of_dumps -s $using:total_procdump_time -ma cftpsai.exe $using:working_directory"\dumps" -accepteula
timeout /T $using:total_procdump_time_close
exit
}
}

View File

@ -0,0 +1,100 @@
<#
.SYNOPSIS
Use EFT's COM interface to configure ARM settings for auditing and reporting.
.DESCRIPTION
Use EFT's COM interface to check status of ARM and reconnect if needed
.PARAMETER serverName
.PARAMETER eftAdminPort
.PARAMETER authMethod
.PARAMETER eftAdminName
.PARAMETER eftAdminPassword
#>
param(
[Parameter(Mandatory=$False)][string]$serverName = "localhost",
[Parameter(Mandatory=$False)][int]$eftAdminPort = 1100,
[Parameter(Mandatory=$False)][int]$authMethod = 1,
[Parameter(Mandatory=$False)][string]$eftAdminName = "",
[Parameter(Mandatory=$False)][string]$eftAdminPassword = ""
)
#------------------------------------------------------------
# Setup logging to a file
#------------------------------------------------------------
#Output <DATE> <TIME> <UTC Offset>
Function getdate
{
Get-Date -Format "MM/dd/yyyy HH:mm:ss K "
}
$currenttime = getdate
#Path to log file
$Logfile = "C:\Users\jbranan\Desktop\ARM-Connection.log"
#Function to accept string input and append to $Logfile
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
#------------------------------------------------------------
# login as admin
#------------------------------------------------------------
try {
$oServer = New-Object -ComObject 'SFTPComInterface.CIServer'
$oServer.ConnectEx( $serverName, $eftAdminPort, $authMethod, $eftAdminName, $eftAdminPassword );
Write-Host "connected"
}
catch {
$errorMessage = $_.Exception.Message;
Write-Host "failed to connect to server ${serverName}: ${errorMessage}"
Exit;
}
#------------------------------------------------------------
# get ARM settings
#------------------------------------------------------------
#Write-Output ("ARMServerName: {0}" -f $oServer.ARMServerName)
if ($oServer.ARMTestConnection())
{
Write-Output ('ARM Test Connection Succeeded.')
$logstring= $currenttime + 'ARM Test Connection Succeeded.'
LogWrite $logstring
if ($oServer.ARMReconnect())
{
Write-Output 'ARM Is Connected.'
$logstring= $currenttime + 'ARM Is Connected.'
LogWrite $logstring
}
else
{
write-output 'Failed To Reconnect ARM.'
$logstring= $currenttime + 'Failed To Reconnect ARM.'
LogWrite $logstring
}
}
else
{
Write-Output ('ARM Test Connection Failed.')
$logstring=$currenttime + 'ARM Test Connection Failed.'
LogWrite $logstring
}
#$oServer.ARMReconnect()
#------------------------------------------------------------
# close resources
#------------------------------------------------------------
$oServer.Close()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($oServer) | out-null
Remove-Variable oServer