My script

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. 

September 3rd, 2015 8:23am

Hi,

My guess is that whatever 'durwfp' is might be causing this. What does the window actually look like though? Does it have any identifiable text?

As for the log issue, you have 'length' misspelled (I do this all the time too) so the test will always fail.

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 8:33am

Hi Mike,

Yeh 'Length':) corerct and well I also tried putting append on two places so now I can see the log file getting appended though but I will change the spelling.

And the pop is completely black no script :(

Do you know something.

Thanks!!

September 3rd, 2015 8:37am

correct** Typooss
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 8:37am

And the pop is completely black no script :(

Sounds like a CMD window, so it's likely that whatever 'durwfp' is is the culprit. You could try using Start-Process to launch this and see if -NoNewWindow helps:

http://ss64.com/ps/start-process.html

Also, now that I look at your rollover closer, you're never actually renaming the existing file. The filename you're specified in the -Path and -Destination parameters are the same.

September 3rd, 2015 8:43am

Yes I am forcing it -Force to put it at the same location. 
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 8:46am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics