Windows Server 2008 – Task Schedule Error 2147746323

December 18, 2017

When you schedule a Task you might run into the Error 2147746323.

The code appears after you schedule an Email Action

image

When you convert this error number to a HEX number it will disclose the root cause.

Use this PowerShell script to convert it to HEX

CLS

$Value = 2147746323

"0x"+ ('{0:x}' -f $Value)

It will look like this :

image

Meaning : The transport failed to connect to the Email server

So you need to investigate where it goes wrong in connecting to the server.

For more codes see here  :

https://msdn.microsoft.com/en-us/library/windows/desktop/aa383604(v=vs.85).aspx

Enjoy!

Advertisements

PowerShell – Crystal Reports COM Object

December 17, 2017

Recently I was going through my files and found (again) Smile the very nice Crystal Reports COM libraries

 

image

As you can see these are more then 15 years old !!

But still works like a charm … many years back I created an example in AutoIT using the CRViewer COM object.

image

Actually the Crystal Reports at that time came with some nice COM libraries, which are still my all time favourites.

And tons of functionality to automate your tasks…

image

It can access all kinds of Database formats using ODBC and native DB connections.

As you can see it also has a multitude of Export and printing abilities.

$Crystal_Report = 1
$Data_Interchange = 2
$Record_Style = 3
$CSV = 5
$Tab_Sep_Val = 6
$CharSepVal = 7
$Text = 8
$TabSepText = 9
$Paginated_Text = 10
$Lotus_23WKS = 11
$Lotus_123WK1 = 12
$Lotus_123WK3 = 13
$Word = 14
$Excel_5 = 21
$Excel_5_Tabular = 22
$ODBC = 23
$HTML32 = 24
$Explorer32 = 25
$Excel_7= 27
$Excel_7_Tabular = 28
$Excel_8 = 29
$Excel_8_Tabluar = 30
$PDF = 31
$HTML40 = 32
$Crystal_Report_7 = 33
$Report_Definition = 34
$RTF = 35
$XML = 36

 

PowerShell COM Backwards compatible ?

So the idea now is to see how PowerShell is able to handle these old COM libraries.

Here we go …  Smile

This script will read a Crystal Report 8.5 report using a MS SQL database data source.

Refreshes the data in the report, Exports it to Excel and next E-mails this to 1 or more recipients.

CLS

$Excel_7= 27

$ServerType = "p2lodbc.dll"
$ServerName = "ServerName"
$databaseName = "DatabaseName"
$user = "UserName"
$pswd = "Password"
 
$vFilenameReport = "C:\Deliveries per customer.rpt"
$vFilenameExport = "C:\Deliveries per customer.xls"

$oApp = New-Object -ComObject "CrystalRuntime.Application" # Com Object

# LogOnServer
    $oApp.LogOnServer($ServerType, $ServerName, $databaseName, $user, $pswd)

# Open Report
  $oRpt = $oApp.OpenReport($vFilenameReport, 0) # 0 / 1

# Report Options
  $oRpt.DiscardSavedData() # DiscardSavedData In Report to REFRESH
  $oRpt.EnableParameterPrompting = $False
  $oRpt.DisplayProgressDialog = $False
  $oRpt.MorePrintEngineErrorMessages = $False

# Export Options
Start-Sleep 2

  # $oRpt.ExportOptions.Reset | out-null
   $oRpt.ExportOptions.DestinationType = 1 # 1=>filesystem 
   $oRpt.ExportOptions.FormatType = $Excel_7  # 27=> Excel 7
   $oRpt.ExportOptions.DiskFileName = $vFilenameExport 

  # $oRpt.ExportOptions.ExcelExportAllPages = $True 
  # $oRpt.Export($True) # Export without prompting = False

   $oRpt.Export($False) # Export without prompting = False

# Send Email
 Send-MailMessage -to Your.Name@Company.com `
-from admin@Company.com `
-Subject "Monthly Email Service" `
-body "Hello !!! `nThis is your personal E-mail service.`nPlease find the updates enclosed.`nUntill next time. `nRegards," `
-Attachments $vFilenameExport `
-smtpserver YourEmailServer  

# Remove Attachment File
   Start-Sleep -s 2
   Remove-Item $vFilenameExport

 

If you schedule this script you have created your own reporting platform.

 

image

Keep in mind that you need to you the 32Bit PowerShell version

image

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

But it doesn’t spoil the fun Smile

And this proves PowerShell is 100% backwards COM compatible !!

 

Enjoy !


SharePoint – Difference between Item level Permission and Item level Security

December 1, 2017

Recently I discovered that in SharePoint there is a difference between Item Level Security and Item Level Permissions.

1. Item level Security

This is the one everyone knows…

You can set user security on each individual doc. in a library or a record in a list.


2. Item Level Permission

For Document libraries you can only modify this using PowerShell (or .NET)

In my opinion this has less performance impact than the Item level Security.

But of course it serves a different purpose too…

So depending on what you need I would definitely consider this option.

Here are the different options :

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.writesecurity.aspx

SPList.WriteSecurity
•    1 = All users can modify all items.
•    2 = Users can modify only items that they create.
•    4 = Users cannot modify any list item.

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.readsecurity.aspx

SPList.ReadSecurity
•    1 = All users have Read access to all items.
•    2 = Users have Read access only to items that they create.

Example :

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
	Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$web = Get-SPWeb -Identity http://YourSP

$list = $web.Lists["Documents"]

"Read Security = " +  $list.ReadSecurity 
"Write Security = " + $list.WriteSecurity


For SharePoint lists you can just use the GUI :

image

Enjoy !


PowerShell – Azure Cloud Shell for PowerShell and Bash

November 3, 2017

Microsoft recently released a new feature called Azure Cloud Shell (for PowerShell and Bash).

To get started you need to log into the Azure Portal.

1. Click this icon

image

2. Choose Bash or PowerShell

image

3. Subscribe

This wil create an Azure File Storage to store your scripts

image

File Storage

Azure Files offers fully managed file shares in the cloud that are accessible via the industry standard Server Message Block (SMB) protocol.

Azure File shares can be mounted concurrently by cloud or on-premises deployments of Windows, macOS, and Linux.

Azure Files enable sharing files between applications running in your virtual machines using familiar Windows APIs or File REST API. Additionally,

Azure File Sync allows caching and synchronization of Azure Files shares on Windows Servers for local access.

image

Once created you can access all Azure resource using PowerShell or Bash resources.

And the scripts will be available online using your PC or even on a Mobile device !


image


Read more here : https://docs.microsoft.com/en-us/azure/cloud-shell/overview

Or watch this movie https://www.youtube.com/watch?v=RhnZ4lJgEnU&MC=SysMagSof&MC=MSAzure

Enjoy!


PowerShell – Using PoSH SSH Module to access Synology NAS

October 21, 2017

You can now access any SSH device using the PoSH SSH module.

Let’s give it a try using a Synology NAS Device.

Make sure that you enable the SSH Access Service

image

Next make sure you have installed the PoSH-SSH module

Find-Module Posh-SSH

image

Next install it using this command (run as Administrator) :

Find-Module Posh-SSH | Install-Module

After installing you can check the commands available

Get-Command -Module Posh-SSH

image

Now you are ready to make a connection Smile

New-SSHSession -ComputerName YourNASDeviceNAME

image

You can check the session info like this

Get-SSHSession
Get-SSHTrustedHost | fl

image

Let’s run some commands

Invoke-SSHCommand -SessionId 0 -Command "ls -all" | select-Object output -expandproperty output | fl

image

Or using this format :

$result = Invoke-SSHCommand -Index 0 -Command "uname -a; cd /; pwd; ls /volume1" 
$result.Output

image

$result = Invoke-SSHCommand -Index 0 -Command "uname -a" 
$result.Output

image

To stop the session use this command :

Remove-SSHSession -Index 0 -Verbose

image

Enjoy !!


PowerShell – Database Choise SQLite vs SQLCE

October 12, 2017

 

Over time I wrote some posts relating to SQLCE as a nice standalone Database platform that can by used in PowerShell or Webmatrix on IIS etc.

Now that MS has announced the end of life of Webmatrix Sad smile

“WebMatrix product support ends on November 1st, 2017”

As Webmatrix runs on MSSQLCE we need to look for alternatives…

“MS SQLCE support will end in July 2021”

One of the most obvious alternative is of course SQLite, which is shipped as part of AutoIT Winking smile

 

Besides this, SQLite has much more to offer then SQLCE :

Comparison http://erikej.blogspot.be/2011/01/comparison-of-sql-server-compact-4-and.html

 

As you can see the size limit is 140 TB and unlimited concurrent users !

And it runs on Windows / Linux / Mac … and as well on Mobile devices.

So this will do for a while … Winking smile

 

SOLUTION :

1. Download the appropriate .NET Assembly for your environment

https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

2. Run this PS code :

Add-Type -Path "C:\Temp\.NET SQLite Library\System.Data.SQLite.dll" 

$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$con.ConnectionString = "Data Source=C:\Temp\.NET SQLite Library\northwindEF.db"

$con.Open()

$sql = $con.CreateCommand()
$sql.CommandText = "SELECT * FROM Customers"
$adapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $sql
$data = New-Object System.Data.DataSet

[void]$adapter.Fill($data)

"Rows # :  " + $data.tables.rows.count
$data.tables.rows | Out-GridView # | ft

3. Test it.

Once you run it you can access the SQLite Database lightning fast …

 

image

 

Some more Tips and Tools you can find here :

http://erikej.blogspot.be/2014/08/sqlite-toolbox-40-visual-guide-of.html

http://erikej.blogspot.be/2014/11/using-sqlite-with-entity-framework-6.html

Enjoy !


PowerShell – Import-Pssession is not Importing Cmdlets for O365 Exchange Online

August 30, 2017

 

I noticed that after connecting to O365 Exchange Online using PowerShell, the connection was done OK.

But I could recognize any of the Cmdlets after connecting Sad smile

 

SOLUTION :

$LiveCred = Get-Credential -credential "patrick.taels@plastiflex.com"
   $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-Module (Import-PSSession $Session -WarningAction SilentlyContinue -AllowClobber) -Global 

 

As you can notice you need to add the Import-Module( … –AllowClobber) –Global Command and Parameters …

Enjoy !