Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

14 September 2017

Solution for Excel opening blank when you double-click a file icon or file name

Problem with running the latest Excel, where i cannot open Excel files when double-clicking the files, but i can drag the files and they open.

Microsoft Support stats the following but non of the proposed solutions resolved the issue.
https://support.microsoft.com/en-us/help/2994633/excel-how-to-troubleshoot-excel-opening-blank-when-you-double-click-a

You can solve it the hard way by just sending the filepath as a command line parameter to Excel!

Create a Excel.cmd file and locate in e.g. c:\program files with the following content

Excel.cmd
start "Opening files with Excel fix" "C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE" %1

Then right click the xlsx file and open with, mark always, and choose another program and find your Excel.cmd file. Using start means the command window closes after excel opens, without start the cmd file is open in the background.

This is the most basic way of sending files to programs and it works for excel too :) 

20 October 2016

Sync an FTP folder using WinSCP commandline

syncftp.cmd

"C:\Program Files (x86)\WinSCP\winscp" /script="C:\FTP-Sync\download.winscp"


download.winscp

open ftp://user:password@server.com/
synchronize local "C:\FTP-Sync\public" /
exit

16 December 2015

FTP RSync alternative on Windows using WinSCP

Downloading only changed files from an FTP folder is something RSync offers on nix systems.
This is one way to achieve the same on Windows.

WinSCP is a Free SFTP, SCP and FTP client for Windows and it is scriptable.

09 December 2015

MsSql Database Storage Usage Monitor Script


Task for monitoring SQL server space usage on multiple servers. 


We have the task scheduled monthly at 1508.





Recursive File Search - a barebone filepath indexing service

Large NAS Folder structures can be difficult to search without an indexing service. In this case we generate a text file with all file paths, names and changedates, allowing easy search on filenames in the structure.




Using a NAS for storing your Windows Domain Users folders

At 1508 we have used a NAS (Synology DS1010+) for handling the users private folders.

The users folder are part of the users private folders and requires that each of the folders are locked down to the specific user so their data is secure. Managing the NTFS ACL security can either be handled by a manuel process or automated using a tool like SetACL by Helge Klein (http://helgeklein.com/) and a shell batch.

We have chosen to utilities a script for security a strict implementation and an easy way of resetting security on all folders in the root.

We created two jobs for managing the ACL's Access Control List, the files are located in the root of the users share on the NAS with the SetACL.exe in the same location.

SetPermission (edit me).cmd

The job can create a single folder and set the permissions, this is used for creating a new user in the domain. 

set userfolder=lpd
rem set security and clear custom settings below
"\\nas\users\SetACL.exe" -on "\\nas1\users\%userfolder%" -ot file -actn ace -ace "n:1508DOMAIN\%userfolder%;p:change" -ace "n:Domain Admins;p:full" -rec cont_obj -actn clear -clr "dacl"
rem remove inherited security
"\\nas\users\SetACL.exe" -on "\\nas1\users\%userfolder%" -ot file -actn setprot -op "dacl:p_c" -rec cont_obj
pause

ResetPermissions.cmd

For allowing the folder structure to be reset we created a batch that used the above line and detected the username based on the foldername.

@echo off

if "%~1"=="?" goto HELP
if "%~1"=="/?" goto HELP
set target=%~dp0%

echo Target must be an attached drive: %target%
FOR /F %%f IN ('DIR %target% /B /AD') DO CALL :executeResetACL %%f
echo Done!
pause
GOTO:EOF

:executeResetACL
rem "%target%SetACL.exe" -on "%target%%1" -ot file -actn setowner -ownr "n:1508DOMAIN\jhe" -rec cont_obj -actn clear -clr "dacl,sacl"
"%target%SetACL.exe" -on "%target%%1" -ot file -actn ace -ace "n:1508DOMAIN\%1;p:change" -ace "n:Domain Admins;p:full" -rec cont_obj -actn clear -clr "dacl"
GOTO:EOF

:HELP
echo  Set ACL change access to the Network Service on the specified path
echo.   
GOTO:EOF

These files have helped us run the domains private user shares for 5 years now...
Feel free to use the scripts as you like.

04 December 2015

Set Opacity in Powershell and cmd Console Windows

With windows 10 we finally have support for opacity in the console, so we can look cool when shelling... the opacity option can be adjusted in the default options.

It came in the first editions of windows 10, but I first found out now, so other might need a nudge to find out too. Several improvements have been implemented: https://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview/



It also kicks in on the PowerShell

20 October 2012

Handling PowerShell Scripts Failure Conditions in TeamCity

PowerShell scripts in TeamCity build steps can be a pain to handle when they fail and you want them to brake the build process.

Part of our OneClick-deployment-for-Sitecore is a build step for production where we run a backup script for the production Sql servers prior to releasing the Sitecore Items with TDS. Some time ago we were hit with the following issue that showed up in the buildlog but did not have any effect on the build process.

This meant that we did not have the backup in place prior to deploying the Sitecore Items!

[10:43:37]Step 3/7: Backup DB (Powershell) (32s)
[10:43:37][Step 3/7] Starting: C:\Windows\system32\cmd.exe /c C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File D:\TeamCity\buildAgent\work\54acd6c7ad57d4b9\BackupScript.ps1 xx prod xx prod 0.0.148.1937 && exit /b %ERRORLEVEL%
[10:43:37][Step 3/7] in directory: D:\TeamCity\buildAgent\work\54acd6c7ad57d4b9
[10:44:09][Step 3/7] Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server '
[10:44:09][Step 3/7] xxxx'. "
[10:44:09][Step 3/7] At D:\TeamCity\buildAgent\work\54acd6c7ad57d4b9\BackupScript.ps1:35 char:22
[10:44:09][Step 3/7] +     $smoBackup.SqlBackup <<<< ($server)
[10:44:09][Step 3/7]     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
[10:44:09][Step 3/7]     + FullyQualifiedErrorId : DotNetMethodException
[10:44:09][Step 3/7]  
[10:44:09][Step 3/7] Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server '
[10:44:09][Step 3/7] xxx'. "
[10:44:09][Step 3/7] At D:\TeamCity\buildAgent\work\54acd6c7ad57d4b9\BackupScript.ps1:35 char:22
[10:44:09][Step 3/7] +     $smoBackup.SqlBackup <<<< ($server)
[10:44:09][Step 3/7]     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
[10:44:09][Step 3/7]     + FullyQualifiedErrorId : DotNetMethodException
[10:44:09][Step 3/7]  
[10:44:10][Step 3/7] Process exited with code 0

The problem was caused by missing disk space on the Sql server (due to many releases and backups) so we were lucky to have a disk space monitor alert from the hosting provider.

Updating the build for handling these PowerShell Exceptions can be done by either updating the return codes for the shell script but can also be achieved with TeamCity's "Build Failure Conditions" with a text validation on the build log.