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', '9.0.0.0')
    $redirects.Add('microsoft.owin', '3.0.1.0')
    $redirects.Add('microsoft.owin.security', '3.0.1.0')

    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($assemble.assemblyidentity.name -eq $casm -And $currentVersion -ne $newVers)
    		{
    			Write-Host "Updating $_ $casm from $currentVersion to $newVers"
    			$assemble.bindingredirect.oldversion = "0.0.0.0-$newVers"
    			$assemble.bindingredirect.newversion = $newVers
    			$requiresSave = $TRUE
    			
    		}
    	}
    }
    
    if($requiresSave){
    	Write-Host "Saving file " $_.FullName
    	$backupPath = $_.FullName + ".$(get-date -f yyyyMMddhhmmss)"
    	
    	Copy-Item -Path $_.FullName -Destination $backupPath
    	$xml.save($_.FullName)
    }
    else{
    	#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 system.net.mail.smtpClient
    $SmtpClient.host = "SMTP Relay"
    $MailMessage = New-Object system.net.mail.mailmessage
    $MailMessage.from = "[email protected]"
    $MailMessage.To.add("[email protected]")
    $MailMessage.IsBodyHtml = 0
    $MailMessage.Subject = $MailSubject
    $MailMessage.Body = $MailBody
    $SmtpClient.Send($MailMessage)
    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