Powershell Error connecting to SharePoint Online using CSOM Assemblies

April 27, 2018

When using a Powershell Script to connect to SharePoint Online I got this error…

msoidcliL.dll : System.IO.FileNotFoundException – SharePointOnlineCredentials

image

Solution :

Update your SP client side Assemblies, which does not rely anymore on Msoidclil.dll

image

image

Once updated the error was gone Smile

Enjoy !

Advertisements

Windows Core IoT – ASP DotNet Core Razor Pages on a Raspberry PI3

April 20, 2018

Continuing on based on my prior posts

.Net Core on RPI3

SQLite on RPI3

I am going to explain how to use Windows IoT and ASP .Net Core on a RPI3.

As of version 2.0 we now can create ASP Razor webpages in .NET Core.

Remember that in the past I made some post about Web Matrix

That is in fact the predecessor of ASP .Net Core. Read more here

How to use Razor Pages in ASP.NET Core 2.0

Start with installing the DotNet Core Template to begin with

Run command :

dotnet new Razor -n ASPnetCoreRazor -o C:\CoreIoT\ASPnetCoreRazor

image

Next Run the Template Application on your Windows PC.

Use command :

cd C:\CoreIoT\ASPnetCoreRazor

dotnet Run

image

Voila as simple as that Smile

image

Next Publish it for Windows IoT on a RPI3 Architecture

Run command :

dotnet publish -r win8-arm


image

Copy the files to your RPI3 from C:\CoreIoT\ASPnetCoreRazor\bin\Debug\netcoreapp2.0\win8-arm\publish

image


Connect to RPI3 using PowerShell remote session and start the ASPNetCoreRazor.exe Application

image

No connection … ? Sad smile

image

SOLUTION :

1. You need to open the Firewall Port 5000 on your RPI3 first.

Run command :

netsh advfirewall firewall add rule name=” ASPnetCoreRazor ” dir=in action=allow protocol=TCP localport=5000


image

2. Modify the Template Program.cs script

And add this line : .UseUrls(http://*:5000)


image

Publish again :

dotnet publish -r win8-arm

image

Copy the files back over to your RPI3 :

C:\CoreIoT\ASPnetCoreRazor\bin\Debug\netcoreapp2.0\win8-arm\publish\


Next connect to RPI3 using PowerShell and start the app ….

.\ASPnetCoreRazor.exe


image

Open the browser and go to : http://rpi3:5000

image

It runs as expected !! Smile

So now we know how to create RAZOR pages, the door is open to start experimenting with the RAZOR syntax.

As well as integrating SQLite database using the ASP .NetCore Razor Front End….

Enjoy !


Windows Core IoT – SQLite on a Raspberry PI3

April 15, 2018

As shown in the previous post you can run use Dotnet Core to compile apps for Windows IoT on a RPI3

See here how to get started with Dotnet Core

On the net you can find how to use Dotnet Core and SQLite :

https://developersoapbox.com/connecting-to-a-sqlite-database-using-net-core/

But the example uses the Dotnet Core v1.0 Framework and run on Windows.

I will show here how to use the latest Dotnet Core v2.0 Framework and publish it for Windows ARM on RPI3 Winking smile

Run command Dotnet new console –n Sqlite –o C:\DotNetCoreApps\Sqlite

And check the result here :

image

Copy the program.cs as backup, and copy the program code from the site above into the program.cs file.

Change the namespace to SQLite (see-n SQLite in first command)

clip_image002

Change the sqlite.csproj file content by adding a few lines

clip_image002

Add these line :

image

<Project Sdk=”Microsoft.NET.Sdk”>

  <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp2.0</TargetFramework>
     <RuntimeIdentifiers>win8-arm;ubuntu.14.04-arm;ubuntu.16.04-arm</RuntimeIdentifiers>
   </PropertyGroup>
   <ItemGroup>
<PackageReference Include=”Microsoft.EntityFrameworkCore.Sqlite” Version=”2.0.2″ />
<PackageReference Include=”SQLitePCLRaw.bundle_green” Version=”1.1.10″ />

  </ItemGroup>
   <ItemGroup>
     <DotNetCliToolReference Include=”Microsoft.EntityFrameworkCore.Tools.DotNet” Version=”2.0.0″ />
   </ItemGroup>
</Project>

Run command : dotnet Restore

image

As you can see it will use some Nuget packages as included in the sqlite.csproj file

Next run this command : dotnet publish -r win8-arm

And copy the files to your RPI3

image

Next open PowerShell do a remote session and run the .\SQLite.exe

image

When the SQLite DB doesn’t exist yet, it will be created automatically.

image

DotNet Core is really a cross-platform language !

It runs flawlessly on a RPI3 – ARM Architecture, by just re-using the same code base we use on a Windows machine Smile

See here for more info on .NET Core Data Access data sources :

https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/

Enjoy !


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!


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!