Support for 2.0 and later versions.
Some times the path string in a report is very long. You can also abbreviate it if you need it, but the path loses its value. It's a good idea to use the built-in APIs to make it a flexible thumbnail path.
Next I'll show you how to use C # code in PowerShell scripts:
Copy Code code as follows:
$newType = @ '
Using System;
Using System.Text;
Using System.Runtime.InteropServices;
Namespace Windowsapilib
{
public class Helper
{
[DllImport ("Shlwapi.dll", CharSet = CharSet.Auto, SetLastError = True)]
Internal static extern bool PathCompactPathEx (System.Text.StringBuilder pszout, String pszsrc, Int32 Cchmax, Int32 Dwflag s);
public static string Compactpath (string Path, int desiredlength)
{
StringBuilder sb = new StringBuilder (260);
if (PathCompactPathEx (SB, Path, Desiredlength + 1, 0))
{return SB. ToString (); }
Else
{return Path;}
}
}
}
'@
Add-type-typedefinition $newType
Once you execute this code, a new one will be created. NET class, which adds a new static method, "Compactpath," and now you can use it like this:
Copy Code code as follows:
Ps> $pshome
C:\Windows\System32\WindowsPowerShell\v1.0
ps> [Windowsapilib.helper]::compactpath ($pshome, 12)
C:\W...\v1.0
ps> [Windowsapilib.helper]::compactpath ($pshome, 18)
C:\Windows...\v1.0
ps> [Windowsapilib.helper]::compactpath ($pshome, 22)
C:\Windows\Sys...\v1.0