{"id":293,"date":"2025-05-20T16:34:51","date_gmt":"2025-05-20T14:34:51","guid":{"rendered":"http:\/\/mariospavlidis.site\/?p=293"},"modified":"2025-05-20T16:34:51","modified_gmt":"2025-05-20T14:34:51","slug":"useful-powershell-commands","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2025\/05\/20\/useful-powershell-commands\/","title":{"rendered":"Useful Powershell commands"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>1. Check if Machine Is Domain Joined<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(Get-WmiObject Win32_ComputerSystem).PartOfDomain<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. View SPNs for a SQL Server Service Account<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">setspn -L domain\\sqlsvcaccount<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Register an SPN for SQL Server<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">setspn -S MSSQLSvc\/sql1.contoso.com:1433 domain\\sqlsvcaccount<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Create a gMSA Account (Domain Admin)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">New-ADServiceAccount -Name gMSASQL01 `<br>  -DNSHostName sql1.contoso.com `<br>  -PrincipalsAllowedToRetrieveManagedPassword \"SQLServersGroup\"<br><br>Test-ADServiceAccount gMSASQL01<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Install gMSA on SQL Server VM<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Install-ADServiceAccount -Identity gMSASQL01<br><br>Test-ADServiceAccount gMSASQL01<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6. Delegate Permissions to gMSA (Constrained)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Set-ADUser -Identity gMSASQL01 `<br>-Add @{msDS-AllowedToDelegateTo=\"MSSQLSvc\/sql2.contoso.com:1433\"}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7. Delegate DNS Record Permissions to a Cluster or Listener<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnscmd \/RecordAdd &lt;domain name> AGListenerName A &lt;IP><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8. View Domain Membership Info<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systeminfo | findstr \/B \/C:\"Domain\"<br>or<br>(Get-WmiObject Win32_ComputerSystem).Domain<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>9. View Delegation Settings in AD (GUI)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Open <strong>Active Directory Users and Computers<\/strong><br>Find your <strong>gMSA or SQL Server object<\/strong><br>Right-click \u2192 <strong>Properties<\/strong> \u2192 <strong>Delegation tab<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>10. Common Permissions for DBA Tasks<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Task<\/th><th>AD Permission Needed<\/th><\/tr><\/thead><tbody><tr><td>Create AG Listener<\/td><td>Create Computer Objects + DNS registration<\/td><\/tr><tr><td>Use gMSA<\/td><td>gMSA retrieval rights + Log on as service (local)<\/td><\/tr><tr><td>Use linked servers w\/ Kerberos<\/td><td>Constrained delegation from gMSA to target SPN<\/td><\/tr><tr><td>SQL Agent file share access<\/td><td>gMSA\/file system permissions (domain-level ACLs)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>11. PowerShell AD Module Cmdlets<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Cmdlet<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>Get-ADUser<\/code><\/td><td>View user\/service account<\/td><\/tr><tr><td><code>Set-ADUser<\/code><\/td><td>Modify user (e.g., delegate)<\/td><\/tr><tr><td><code>New-ADServiceAccount<\/code><\/td><td>Create a gMSA<\/td><\/tr><tr><td><code>Install-ADServiceAccount<\/code><\/td><td>Install gMSA on SQL Server<\/td><\/tr><tr><td><code>Get-ADComputer<\/code><\/td><td>Inspect SQL Server host or cluster node<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Check if Machine Is Domain Joined (Get-WmiObject Win32_ComputerSystem).PartOfDomain 2. View SPNs for a SQL Server Service Account setspn -L domain\\sqlsvcaccount 3. Register an SPN for SQL Server setspn -S MSSQLSvc\/sql1.contoso.com:1433 domain\\sqlsvcaccount 4. Create a gMSA Account (Domain Admin) New-ADServiceAccount -Name gMSASQL01 ` -DNSHostName sql1.contoso.com ` -PrincipalsAllowedToRetrieveManagedPassword &#8220;SQLServersGroup&#8221;Test-ADServiceAccount gMSASQL01 5. Install gMSA on SQL Server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"blocksy_meta":[],"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":1,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":294,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/293\/revisions\/294"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}