Loading...

9 years ago I started my project of “Create Real Fake Names” with PowerShell.

Then It was a script with some function that created random given names and surnames to use in lab environments.
And the project has been posted to my old blogs and to Technet gallery.

The problem that I have had in the past is that the source url for Swedish names have been changed now and then.

My project will change a little bit now when I’m updating my blog and where I put my scripts and projects.
I have started to publish this project to my PowerShell Github repository, https://github.com/FredrikWall/PowerShell.
Under Real Fake Names.

News to the project:

  • From now on I will publish my functions for this project separated and with example scripts.
  • Using API for Sweden
  • Changed UK to England and Wales
  • Added support for:
    Denmark (Given names)
    Finland (Given names)
    Norway (Given and Surnames)
  • Import files will be published as well under the folder Imported
Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Hello,

this is my first presentation of me, this blog, my youtube channel and my twitter.
The blog have some content, I’m relative active on Twitter and my Youtube channel will be more active soon.

Presentation of Fredrik Wall - YouTube

The slides from the presentation can be downloaded from here.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I posted this tool the first time in 2014 on Poweradmin.se,
when I was working with MSI packaging.

The tool is now updated and published to my Github repository.

MSI Information tool is a tool that will get:

  • Product Name
  • Product Version
  • Product Code
  • Manufacturer

Directly from the MSI file.

Browse for the msi file, press Get.
Mark the text you want to copy and then press copy and you have the information you want!

A small but nice tool if you are working with application distribution or MSI packaging.

You can download it herewith PowerShell Studio source file and .ps1 file.
Feel free to look at the source to learn more about creating graphical Tools with PowerShell Studio.

If you don’t like PowerShell GUI tools but wants to get information from MSI files.
Take a look at my Get-MSIInformation function below:

function Get-MSIInformation {
	<#
	.SYNOPSIS
		Gets MSI Information from a MSI file
	.DESCRIPTION
		This function will open up a MSI file and get the property information that you want
	.PARAMETER FilePath
		Path to the MSI file
	.PARAMETER Property
		The Property that you want to get information from
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductName"
	
		My MSI file
	
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductVersion"
	
		1.0.0.0
	
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductCode"
	
		{CFF8B5ED-0A4D-4EDD-9159-32FE1D31C9E3}
	.NOTES
		Author: 	Fredrik Wall
		Email:		fredrik@poweradmin.se
		Created:	05/03/2014

	
		The original code is taken from a MSI version code powershell function that I found
		on the internet. And then I tweaked it to suit my needs to get all properties, one by one.
	
	#>
	param (
        [IO.FileInfo]$FilePath,
        [String]$Property
    )

    try {
        $myWindowsInstaller = New-Object -com WindowsInstaller.Installer
        $myMSIDatabase = $myWindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null,$myWindowsInstaller, @($FilePath.FullName, 0))

        $myView = $myMSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $myMSIDatabase, ("SELECT Value FROM Property WHERE Property = '$property'"))

        $myView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $myView, $Null)

        $myRecord = $myView.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $myView, $Null)

        $myMSIInformation = $myRecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $myRecord, 1)

        return $myMSIInformation
		
    } catch {
        throw "Failed to get MSI information. Error: {0}." -f $_
    }
}
Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I posted this tool the first time in 2014 on Poweradmin.se,
when I was working with MSI packaging.

The tool is now updated and published to my Github repository.

MSI Information tool is a tool that will get:

  • Product Name
  • Product Version
  • Product Code
  • Manufacturer

Directly from the MSI file.

Browse for the msi file, press Get.
Mark the text you want to copy and then press copy and you have the information you want!

A small but nice tool if you are working with application distribution or MSI packaging.

You can download it herewith PowerShell Studio source file and .ps1 file.
Feel free to look at the source to learn more about creating graphical Tools with PowerShell Studio.

If you don’t like PowerShell GUI tools but wants to get information from MSI files.
Take a look at my Get-MSIInformation function below:

function Get-MSIInformation {
	<#
	.SYNOPSIS
		Gets MSI Information from a MSI file
	.DESCRIPTION
		This function will open up a MSI file and get the property information that you want
	.PARAMETER FilePath
		Path to the MSI file
	.PARAMETER Property
		The Property that you want to get information from
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductName"
	
		My MSI file
	
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductVersion"
	
		1.0.0.0
	
	.EXAMPLE
		Get-MSIInformation -FilePath "mymsi.msi" -Property "ProductCode"
	
		{CFF8B5ED-0A4D-4EDD-9159-32FE1D31C9E3}
	.NOTES
		Author: 	Fredrik Wall
		Email:		fredrik@poweradmin.se
		Created:	05/03/2014

	
		The original code is taken from a MSI version code powershell function that I found
		on the internet. And then I tweaked it to suit my needs to get all properties, one by one.
	
	#>
	param (
        [IO.FileInfo]$FilePath,
        [String]$Property
    )

    try {
        $myWindowsInstaller = New-Object -com WindowsInstaller.Installer
        $myMSIDatabase = $myWindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null,$myWindowsInstaller, @($FilePath.FullName, 0))

        $myView = $myMSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $myMSIDatabase, ("SELECT Value FROM Property WHERE Property = '$property'"))

        $myView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $myView, $Null)

        $myRecord = $myView.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $myView, $Null)

        $myMSIInformation = $myRecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $myRecord, 1)

        return $myMSIInformation
		
    } catch {
        throw "Failed to get MSI information. Error: {0}." -f $_
    }
}
Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have been posting my tools and code to my old blogs and to the technet gallery before.
But from now on I will be posting my code to my PowerShell Github repository.
And in the blog posts as I have done in the past.

https://github.com/FredrikWall/PowerShell

First out is my Invoke-PnPReScan script.

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

When working with client management and deployment you some times need to do a plug n play rescan when installing drivers.
Using device manager and right click and click on Scan for Hardware changes is not an alternetive then.

Using Microsofts Devcon.exe file with Rescan is an alternetive.
But then you need to distribute that file to your clients and run it.

When we did the PowerShell GeekEnd with the PowerShell User Group Sweden in November this was a question that was up
when we started to talk about creating cool stuff with PowerShell.

We ended up finding a PowerShell solution that was written as an example for using C# code with PowerShell.
And in my solution “Invoke-PnPReScan.ps1” I use that plus a solution for start PowerShell as administrator.
Because this script need to be running as administrator or else nothing will happen.

<#
.SYNOPSIS
	This script performs an Plug n Play Device ReScan
.DESCRIPTION
	This script performs an Plug n Play Device ReScan
.PARAMETER WaitTime
	The wait time in seconds for the devices to be ready after ReScan
.EXAMPLE
    Invoke-PnPReScan.ps1 -WaitTime 30
.NOTES
        NAME:      	Invoke-PnPReScan.ps1
		AUTHOR:    	Fredrik Wall, fredrik@poweradmin.se
		BLOG:       http://www.fredrikwall.se
        CREATED:	11/19/2017
        VERSION:    1.0
#>

[CmdletBinding()]
Param (
	[Parameter(Mandatory=$false)]
	[string]$WaitTime = '20'
)

# Run the script as Administrator
# Some code is from Ben Armstrongs blog post:
# https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/09/23/a-self-elevating-powershell-script/

# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
 
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

if (!($myWindowsPrincipal.IsInRole($adminRole))) {
   # We are not running "as Administrator" - so relaunch as administrator
   Write-Output "Starting PowerShell As Administrator"

   # Create a new process object that starts PowerShell
   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
   
   # Specify the current script path and name as a parameter
   $newProcess.Arguments = $myInvocation.MyCommand.Definition;
   
   # Indicate that the process should be elevated
   $newProcess.Verb = "runas";
   
   # Start the new process
   [System.Diagnostics.Process]::Start($newProcess) | Out-Null
   
   # Exit from the current, unelevated, process
   exit
}


function InitDeviceClass

{
    # Function from Matt Bielman
    # https://blogs.msdn.microsoft.com/mattbie/2010/02/23/how-to-call-net-and-win32-methods-from-powershell-and-your-troubleshooting-packs/ 


    [string]$SourceCode =  @"

    using System.Runtime.InteropServices;

    using System;

   

    namespace mattbie.examples.devices

    {

        // These are the native win32 methods that we require

        internal static class NativeMethods

        {

            [DllImport("cfgmgr32.dll", SetLastError = true, EntryPoint = "CM_Locate_DevNode_Ex", CharSet = CharSet.Auto)]

            public static extern UInt32 CM_Locate_DevNode_Ex(ref UInt32 DevInst, IntPtr DeviceID, UInt64 Flags, IntPtr Machine);

 

            [DllImport("cfgmgr32.dll", SetLastError = true, EntryPoint = "CM_Reenumerate_DevNode_Ex", CharSet = CharSet.Auto)]

            public static extern UInt32 CM_Reenumerate_DevNode_Ex(UInt32 DevInst, UInt64 Flags, IntPtr Machine);

 

            [DllImport("cfgmgr32.dll", SetLastError = true, EntryPoint = "CMP_WaitNoPendingInstallEvents", CharSet = CharSet.Auto)]

            public static extern UInt32 CMP_WaitNoPendingInstallEvents(UInt32 TimeOut);

        }

       

        // This class houses the public methods that we'll use from powershell

        public static class StaticMethods

        {

       

            public const UInt32 CR_SUCCESS = 0;

            public const UInt64 CM_REENUMERATE_SYNCHRONOUS = 1;

            public const UInt64 CM_LOCATE_DEVNODE_NORMAL = 0;

           

            public static UInt32 RescanAllDevices()

            {

                //only connect to local device nodes

                UInt32 ResultCode = 0;

                IntPtr LocalMachineInstance = IntPtr.Zero;

                UInt32 DeviceInstance = 0;

                UInt32 PendingTime = 30000;

 

                ResultCode = NativeMethods.CM_Locate_DevNode_Ex(ref DeviceInstance, IntPtr.Zero, CM_LOCATE_DEVNODE_NORMAL, LocalMachineInstance);

                if (CR_SUCCESS == ResultCode)

                {

                    ResultCode = NativeMethods.CM_Reenumerate_DevNode_Ex(DeviceInstance, CM_REENUMERATE_SYNCHRONOUS, LocalMachineInstance);

                    ResultCode = NativeMethods.CMP_WaitNoPendingInstallEvents(PendingTime);

                }

                return ResultCode;

            }

        }

    }

"@

 

    # use the powershell 2.0 add-type cmdlet to compile the source and make it available to our powershell session
    add-type -TypeDefinition $SourceCode
}

Write-Output "Plug n Play Devices before ReScan: $((Get-PnpDevice *).count)"
Write-Output "Doing a Plug n Play Device ReScan"
# Load up our C# code
InitDeviceClass

# Call the RescanAllDevices method
[mattbie.examples.devices.staticmethods]::RescanAllDevices() | Out-Null

Write-Output "Waiting in $WaitTime seconds for the devices"
Start-Sleep -Seconds $WaitTime

Write-Output "Plug n Play Devices after ReScan: $((Get-PnpDevice *).count)"

I think this is really nice.
To be able to do this from PowerShell and without a .exe file.

Hope this can help more people!

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview