Get .NET Framework Version of an assembly (dll/exe) using PowerShell

i just had to find the required framework version for a compiled .NET assembly (just to make sure, that the selected Application Pool in IIS was set to the righte Framework Version).

——–

$fileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
 Filter = 'Assemblies (*.dll & *.exe)|*.dll'
 MultiSelect = $true}
 [void]$fileBrowser.ShowDialog()
 $files = $fileBrowser.FileNames
  
 foreach($file in $files)
 {
 $version = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($file).ImageRuntimeVersion;
 echo "$($file) is using Framework: $version"
 }
 

————–

Use PowerShell to Back Up System State Prior to Making Changes

Did you know you can use PowerShell to back up the system state?

Understanding the Computer Restore cmdlets

One of the easiest ways to ensure system reliability is to create a restore point prior to making potentially damaging changes. In this way, if a problem arises, it is rather simple to roll back the changes. In Windows PowerShell, the easy way to create a restore point is to use the Windows PowerShell cmdlets. These cmdlets require administrator rights (due to access to protected registry keys and other vital configuration files). Therefore, you need to right-click the Windows PowerShell icon and select Run As Administrator from the Action menu. Keep in mind that these cmdlets only work on client systems later than Windows XP. These cmdlets do not work on server versions of the operating system.

 

Continue reading

Finding process that locks a DLL

You want to replace a dll on a system, but you get access denied, although you’re admin, have the necessary rights.. so which process is locking the particular file/library. I know, there is handles.exe from Sysinternal Suite, and plenty other tools that do the trick.But, you don’t need third-party tools to get the answer, just use tasklist.exe or PowerShell.  

Continue reading

Getting registry last write time with PowerShell

All registry keys have a value associated with called the Last Write Time. This is analogous to the last modification time for a file. When ever the registry key or one if its values has been created, modified, or deleted the value is updated to the current local system time. Unfortunately, there is no Last Write Time associated with a registry value, but it can be infered from the Last Write Time of the key.

Here is a PowerShell script to read the Last Write Time for a registry key.

Usage:

Get-RegKeyLastWriteTime.ps1  

Continue reading

Scan IP range using ping

IP scanner for the poor ones Zwinkerndes Smiley

Just open up a cmd.exe and change the ip range..

C:\>FOR /L %x in (1,1,255) do ping -n 1 192.168.2.%x | find /I "reply" >> c:\temp\pingresult.txt

The above command uses a FOR loop to ping each device and looks for "Reply" in the output. If there is a "Reply" then the host is up.. Results will be written to C:\temp\pingresults.txt

Or the PowerShell version:

C:\> 1..255 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send("192.168.2.$_") } | where-object {$_.Status -eq "success"} | select Address

Continue reading

PowerShell: About SessionConfiguration and how to change them

Remote Access Without Admin Privileges

In PowerShell v.2, remote access is available only to users who hold local administrator privileges. So, even if you do have appropriate remote access to a machine, , you cannot remotely access the system if you are not an Admin. This is not a technical limitation, though, just a safe default. You should use this line to change it :

Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI

PowerShell: Sort-Object

You can use Sort-Object to sort simple variable types. Have a look at the following:

‘Tom’, ‘Chris’, ‘Judy’, ‘Alan’ | Sort-Object

Input can come from a different command. If you’d like to get seven random lottery numbers, you should try this:

1..49 | Get-Random -Count 7 | Sort-Object

You’ll find that when you feed complex objects into Sort-Object, you should specify the object property you want to sort on (or else Sort-Object will pick one by itself):

Get-ChildItem $env:windir | Sort-Object Length

Here are some more examples:

Get-HotFix | Sort-Object InstalledOn

Get-ComputerRestorePoint | Sort-Object Description