How to check powershell errors when running powershell from task scheduler

You can use the following method.

Add this to your powershell script in various places

“Start!” | Out-File c:\mylog.txt

then use try/catch method to catch the errors

#Get data from database and export to file
try{

“SQL Starts” | Out-File c:\mylog.txt

YOUR CODE HERE
} catch [Exception]
{
“Error: {0}” -f $_.Exception.Message | Out-File c:\mylog.txt
$error | Out-File c:\mylog.txt
}

“End” | Out-File c:\mylog.txt

then check your error log file for issue.

 

It happens that the script wasn’t always working and after getting it sorted I have found this

Error: The term ‘Invoke-SqlCmd’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Invoke-SqlCmd : The term ‘Invoke-SqlCmd’ is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is

To fix the problem i had to add the following to the begining of the script

# Import the SQL Server Module.
Import-Module Sqlps -DisableNameChecking;

This has fixed the problem.

 

 

 

 

 

 

 

How to redirect root directory in IIS to something else

Open up IIS install Rewrite module

https://www.iis.net/downloads/microsoft/url-rewrite

then navigate to roo

Your site-> URL Rewrite -> Add new Inboud Blank Rule (This ideally should be first in the top level) then

Requested URL -> Matches the Patter

Using -> Regular Expression

Patter -> ^$

Action -> Action Type – > Redirect
Redirect URL -> Your Site to which you want redirect the root (This can be a sub folder)

Redirect Type (301) Permanent this means that the browser will keep the info and will no need to make a request next time to your server.

Tick  – Stop process other rules.

Enjoy!

 

 

IPHONE 7 Best Black Friday Deal £25.99

ENTER: BLACKNOV32 to get £100 off

http://www.mobiles.co.uk/apple-iphone-7-32gb-rose-gold.html?tid=EF5QMAUG16&affiliate=awinm-103504&awc=380_1479397393_8a8e244caf2f85401ce8be255dbe4ed0&utm_source=Awin&utm_medium=Affiliate&utm_campaign=TechRadar

 

£225.00 handset cost

  • Unlimited mins
  • 2GB data
  • Unlimited texts
Only

£25.99

Per month / 24 month

Voucher -£100.00
= Save-£100.00

  Total
= £25.99 per month
To pay today Total
= £ 125.00