PowerShell.exe -windowstyle hidden {
#Set windowtitle
$host.ui.RawUI.WindowTitle = "NAME_GET"
import-module psftp
#Create logging functionality
Function Write-Log
{
Param([string]$Logstring, [boolean]$NewFile)
if ($NewFile -eq $True) {
(get-date).ToString() + " " + $Logstring | out-file -filepath 'C:\tls\log\nameget_ps.log'
}
else
{
(get-date).ToString() + " " + $Logstring | out-file -filepath 'C:\tls\log\nameget_ps.log' -append
}
#Check the logifle to be smaller than 10MB, otherwise do a rollover
get-item C:\tls\log\nameget_ps.log | ForEach-Object {
if ($_.lenght -ge 10MB) {
(get-date).ToString() + " " + "Performing a logfile rollover" | out-file -filepath 'C:\tls\log\nameget_ps.log' -Append
move-item -Path C:\tls\log\nameget_ps.log -Destination C:\tls\log\nameget_ps.log -Force
(get-date).ToString() + " " + "Logfile rollover completed succesfully" | out-file -filepath 'C:\tls\log\nameget_ps.log'
}
}
}
Write-Log "Script started" $True
# Create the username / password object
$PassWord = ConvertTo-SecureString "123456789" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential("admin",$Password)
#Test if we are the active FT server
durwfp -t 0 -p itm
Write-Log "Testing if we are the active FT server (0 = active) : $LASTEXITCODE" $False
#Open the FTP connection
Write-Log "Opening the FTP connection" $False
set-ftpconnection -Credentials $Credentials -server 192.168.37.1 -session NAMEGET -UsePassive
if($LASTEXITCODE -eq 0)
{
Write-Log "Testing if the FP connection is still open" $False
#Open the FTP connection if it is not open anymore
if(@(get-ftpconnection -session NAMEGET).Count -lt 1)
{
Write-Log "Re-Opening the FTP connection" $False
set-ftpconnection -Credentials $Credentials -server 138.57.146.201 -session NAMEGET -UsePassive
}
else {Write-Log "FTP connection is still open" $False}
#Download the nomination file
Write-Log "Downloading the nomination file" $False
Get-FTPItem -Session NAMEGET -Path /NAMEC/Prod/In/NAMEC2ACC01.DAT -LocalPath C:\Reports\Prodis2FWSACC -Overwrite
#Start the sleep timer
Write-Log "Cycle completed, going to sleep for 120000 msec" $False
#Test if we still are the active FT server
durwfp -t 0 -p itm
Write-Log "Testing if we are the active FT server (0 = active) : $LASTEXITCODE" $False
}
}
The log file cannot get appended, it only gets the recent log somehow. and there is a window pop up when the script runs even though I have put window style hidden.
Can anybody who has time help plz.