Show me the $PowerShell.

  • Banned

    What have you scripted out in order to make your job as an IT professional better?

    I wanted to share a pretty awesome script for swapping out configuration file ties.

    #Specify what assemblies and what versions
    $redirects = @{}
    $redirects.Add('newtonsoft.json', '')
    $redirects.Add('microsoft.owin', '')
    $redirects.Add('', '')

    Get-ChildItem "..**" -Filter *.config |
    Foreach-Object {
    #Write-Host "Processing file $_"

    #Write-Host "Processing file " $_.FullName
    [xml]$xml = (Get-Content $_.FullName) -as [Xml]
    $requiresSave = $FALSE
    foreach($assemble in $xml.configuration.runtime.assemblybinding.dependentassembly)
    	foreach($casm in $redirects.keys){
    		$newVers = $redirects.Get_Item($casm)
    		$currentVersion = $assemble.bindingredirect.newversion
    		if($ -eq $casm -And $currentVersion -ne $newVers)
    			Write-Host "Updating $_ $casm from $currentVersion to $newVers"
    			$assemble.bindingredirect.oldversion = "$newVers"
    			$assemble.bindingredirect.newversion = $newVers
    			$requiresSave = $TRUE
    	Write-Host "Saving file " $_.FullName
    	$backupPath = $_.FullName + ".$(get-date -f yyyyMMddhhmmss)"
    	Copy-Item -Path $_.FullName -Destination $backupPath
    	#Write-Host "File skipped $_"


    Also, does code tagging work in NodeBB?

  • Banned

    I wrote this powershell script. It quries LMTools (used by autodesk, Tekla and may others for network seats.) Checks if all the seats (X) are in use, and if so sends an email with a list of all the computers with it open (we send it to supervisors, incase people are complaining about not being able to use it they know who's not really using it and can tell them to close it). It writes a text file when it's true, so on the next run it does not send an email again if the condition is still true. One it has been false it will delete the txt file and can then send an email again. I schedule it as a task every 30min. with the text file check in their it prevents them from getting an email every 30min. They only get an email when the full usage first happens each instance.

    #This Script Queries LMTools and Sends and Email with usage when full
    #Written by Jason 
    #X Should be Equal to Total Number of Seats
    $Email = cd "C:\Program Files\Autodesk Network License Manager\"
    $Lmtools = .\lmutil.exe lmstat -f [LicesneNumber]
    $Body = $Lmtools -replace ",","`n"
    If (($Lmtools -like '*Total of X licenses in use*') -and (!(Test-Path -Path C:\Scripts\Autodesk.txt -PathType Leaf))){$MailBody= $Body + $Email.mail
    $MailSubject= "Autodesk License Full"
    $SmtpClient = New-Object
    $ = "SMTP Relay"
    $MailMessage = New-Object
    $MailMessage.from = "[email protected]"
    $MailMessage.To.add("[email protected]")
    $MailMessage.IsBodyHtml = 0
    $MailMessage.Subject = $MailSubject
    $MailMessage.Body = $MailBody
    New-Item 'C:\Scripts\Autodesk.txt' -type file -force -value 1
    ElseIf  (!($Lmtools -like '*Total of X licenses in use*')) {Remove-Item 'C:\Scripts\Autodesk.txt'
    Else {Exit

Log in to reply