Skip to content

Mike Simmons

My Workbench

  • Home
  • LinkedIn
  • Home
  • Programming
  • PowerShell Tid Bits #1

PowerShell Tid Bits #1

Posted on July 28, 2017March 16, 2018 By Mike No Comments on PowerShell Tid Bits #1
PowerShell, Programming

The more I use power shell the more I realize you can do just about anything you could do with visual studio and C#. I haven’t found a comprehensive source for all the little differences between C# and powershell but the following are some things to take note of:

First, PowerShell seems to have access to the entire .NET framework however it’s import to remember that you may need to adjust PowerShell to run at the version level you require. You just locate where your powershell.exe and powershellise.exe are located and edit the powershell.exe.config and powershellise.exe.config files respectfully. ( source: https://stackoverflow.com/questions/2094694/how-can-i-run-powershell-with-the-net-4-runtime )

Example:

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>

 

You can even add parts of the .NET framework that aren’t loaded automatically with (source: https://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html )

Add-Type -Path "Path to .dll file"

 

If you wish to call aspects of the .net frame work it’s extremely easy to do for instance say you wanted to do string.IsNullOrEmpty(stringToTest) well in PowerShell you would do the following:

$stringToTest = ""

Write-Host [string]::IsNullOrEmpty($stringToTest)

I haven’t yet found a way to do the C# string $”Value1={$class.Value1}” in PowerShell in such a neat and simple way. When you do that same thing in PowerShell you just return the class object rather then the value you wanted. So in order to achieve that same result you would need to do

Write-Host "Value1=" + $class.Value

Tags: POWERSHELL

Post navigation

❮ Previous Post: Sophos UTM IPv6 Ping/NAT issue
Next Post: PowerShell exporting data easily from MSSQL into a CSV ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

Pages

  • LinkedIn

Recent Posts

  • PowerShell Anti-Idle Script
  • WSUS MMC Crash Due To XML Invalid Character!
  • Open Maintenance – Docker & CentOS 7
  • Powershell script to create user home directory and DFS namespace target
  • C# save DataTable to CSV easily

Recent Comments

    Archives

    • August 2022
    • March 2018
    • July 2017
    • August 2015

    Categories

    • Active Directory
    • C#
    • CentOS
    • Docker
    • GrayLog
    • MSSQL
    • Networking
    • PowerShell
    • Programming
    • Uncategorized
    • Windows
    • XML

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2023 Mike Simmons.

    Theme: Oceanly by ScriptsTown