• Home
  • PS
  • C#
  • Perl
  • MSSQL
  • MariaDB
  • Linux
  • Docker
  • MacOS
  • PG
  • Exchange Server
  • Windows
  • Other

Working with ODBC Connections in Powershell

Details
Written by: po3dno
Category: Power Shell
Created: 23 September 2024
Hits: 306

This post explains how to work with ODBC connections in Powershell. Powershell 4 introduced new cmdlets that make it very easy to create and manage ODBC connections. We use the .NET assembly system.data.odbc.odbcconnection to use ODBC connections present on the system to query the database.

ODBC connections in Powershell 4.0 and higher

Powershell 4 introduced these 4 cmdlets to create, manage and remove ODBC connections. If you for some reason still are on Powershell 3.0, I recommend you to upgrade to Powershell 5.0 which is the newest version at the time of this blog post. Managing ODBC connections in Powershell 3 or older is not fun and requires you to either modify registry or use an .exe file to manage them for you.

  • Add-OdbcDsn
  • Get-OdbcDsn
  • Remove-OdbcDsn
  • Set-OdbcDsn

Read more …

Search update

Details
Written by: po3dno
Category: Power Shell
Created: 03 July 2024
Hits: 211

(New-Object -ComObject Microsoft.Update.Session).CreateupdateSearcher().Search("IsHidden=0 and IsInstalled=0").Updates | Select-Object Title

 

Stop-Service -Name BITS, wuauserv -Force
Remove-ItemProperty -Name AccountDomainSid, PingID, SusClientId, SusClientIDValidation -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\ -ErrorAction SilentlyContinue
Remove-Item "$env:SystemRoot\SoftwareDistribution\" -Recurse -Force -ErrorAction SilentlyContinue
Start-Service -Name BITS, wuauserv
wuauclt /resetauthorization /detectnow
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()

New-ISOFileFromFolder

Details
Written by: po3dno
Category: Power Shell
Created: 18 December 2023
Hits: 378

Function New-ISOFileFromFolder{
    <#
        .SYNOPSIS
        Creates an ISO file from a filepath
    #>
    param(
        [Parameter(Mandatory=$true)]
        [String]$FilePath,
        [Parameter(Mandatory=$true)]
        [String]$Name,
        [Parameter(Mandatory=$true)]
        [String]$ResultFullFileName
    )
    write-host "Creating ISO $Name" -ForegroundColor Green  

    $fsi = New-Object -ComObject IMAPI2FS.MsftFileSystemImage
    $dftd = New-Object -ComObject IMAPI2.MsftDiscFormat2Data
    $Recorder = New-Object -ComObject IMAPI2.MsftDiscRecorder2

    $fsi.FileSystemsToCreate = 7
    $fsi.VolumeName = $Name
    $fsi.FreeMediaBlocks = 1000000  #default 332800

    
    $fsi.Root.AddTreeWithNamedStreams($FilePath,$false)


    
    $resultimage = $fsi.CreateResultImage()
    $resultStream = $resultimage.ImageStream


    Write-IStreamToFile $resultStream $ResultFullFileName
    
}

Read more …

add list users with random password

Details
Written by: po3dno
Category: Power Shell
Created: 14 November 2023
Hits: 1415

function Get-RandomPassword {
    param (
        [Parameter(Mandatory)]
        [int] $length,
        [int] $amountOfNonAlphanumeric = 1
    )
    Add-Type -AssemblyName 'System.Web'
    return [System.Web.Security.Membership]::GeneratePassword($length, $amountOfNonAlphanumeric)
}

"user1

user2" -split "`n" | %{$user = $_; $pwdplain = $(Get-RandomPassword 8); New-ADUser -Name $user -AccountPassword $(ConvertTo-SecureString -String $pwdplain  -AsPlainText -Force) -Enabled $true; write-host $user $pwdplain}

Set A Windows Service Log On Account and Password with PowerShell

Details
Written by: po3dno
Category: Power Shell
Created: 06 February 2023
Hits: 526

The Set-Service cmdlet changes the properties of a service, along with the starting and stopping of a service.

Before setting the log-on account information for a service, we need to capture the credentials. The credentials can come from user input:

# Prompt for credentials
$Credential = Get-Credential

# Prompt for credentials with message
$Credential = Get-Credential -UserName domain\user -Message 'Enter Password for Service Account'

Read more …

  1. Test-RebootRequired
  2. PowerShell equivalents for Repadmin commands
  3. Рекурсивный merge AVHDX
  4. secedit

Page 1 of 11

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Login Form

  • Forgot your password?
  • Forgot your username?

Statistics

  • Users 2
  • Articles 164
  • Articles View Hits 148993