Powershell and SQL Server – 3- Script SQL Server Logins with SMO

The Script is to quickly script out Login from Single or Multiple instance

cls

$SQLserverDB=@() 
$SQLserverDB=Get-Content "C:\PowershellScript\ServerList.txt"
    foreach($SqlServer in $SQLserverDB)
    {
        $server = New-Object Microsoft.SqlServer.Management.Smo.Server($SqlServer)
       
        Write-Host "---Login Script of :"$server"---" -ForegroundColor Yellow

        foreach($login in $Logins)
        {
        $login.Name

           $LoginName=$login.Name
           
           $server.Logins[$LoginName].Script()
        }
    }

LoginScript

Leave a Reply

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