{"id":33,"date":"2024-03-26T13:59:11","date_gmt":"2024-03-26T13:59:11","guid":{"rendered":"https:\/\/myallcodes.in\/?page_id=33"},"modified":"2024-04-30T16:08:53","modified_gmt":"2024-04-30T16:08:53","slug":"power-shell-scripts","status":"publish","type":"page","link":"https:\/\/myallcodes.in\/index.php\/power-shell-scripts\/","title":{"rendered":"Power Shell Scripts"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"># Sometimes we need to get the host name of PDC then we can use this code\/script<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$domainController = (&#91;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).DomainControllers&#91;0].NameWrite-Host \u201cDomain Controller Hostname: $domainController\u201d<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"># <a href=\"https:\/\/myallcodes.in\/index.php\/2024\/03\/27\/to-get-the-all-groups-and-members-details-from-active-directory-using-power-shell-script-and-output-will-be-store-in-csv-file\/\">To get the all groups and members details from Active directory using Power Shell script and output will be store in csv file<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Import-Module ServerManager\nAdd-WindowsFeature RSAT-AD-PowerShell\n\n# Import the Active Directory module\nImport-Module ActiveDirectory\n\n# Specify the distinguished name of your domain\n$domainDN = \"DC=test,DC=com\"\n\n# Create an array to store results\n$results = @()\n\n# Get all groups in Active Directory\n$groups = Get-ADGroup -Filter *\n\n# Check if any groups are found\nif ($groups.Count -eq 0) {\n    Write-Host \"No groups found in Active Directory.\"\n}\nelse {\n    # Iterate through each group and get its members\n    foreach ($group in $groups) {\n        $groupName = $group.SamAccountName\n        $groupInfo = New-Object PSObject -Property @{\n            'GroupName' = $groupName\n            'Members'   = \"\"\n        }\n\n        Write-Host \"Processing Group: $groupName\"\n\n        # Get group members using the Active Directory module\n        $groupMembers = Get-ADGroupMember -Identity $groupName\n\n        # Check if any members are found\n        if ($groupMembers.Count -eq 0) {\n            Write-Host \"  No members found for group: $groupName\"\n        }\n        else {\n            $memberNames = $groupMembers | ForEach-Object {\n                $_.SamAccountName + \" (\" + $_.Name + \")\"\n            }\n\n            $groupInfo.Members = $memberNames -join ', '\n            Write-Host \"  Members: $($groupInfo.Members)\"\n        }\n\n        # Add the group information to the results array\n        $results += $groupInfo\n    }\n\n    # Export the results to a CSV file\n    $csvPath = \"C:\\temp\\OutputFile.csv\"\n    $results | Export-Csv -Path $csvPath -NoTypeInformation\n\n    Write-Host \"Script Execution Completed. CSV file has been created at: $csvPath\"\n}\n\n\n\nGet-ADGroupMember -Identity \"Domain Admins\" | Select-Object SamAccountName,Name | Export-Csv -Path \"C:\\Temp\\OutputFile.csv\" -NoTypeInformation\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"># <a href=\"https:\/\/myallcodes.in\/index.php\/2024\/04\/30\/powershell-command-to-get-the-os-and-hardware-complete-details\/\">PowerShell command to get the OS and Hardware complete details<\/a><\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&#8220;Get-ComputerInfo&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"509\" height=\"732\" src=\"https:\/\/myallcodes.in\/wp-content\/uploads\/2024\/04\/get-info-1.jpg\" alt=\"\" class=\"wp-image-109\" srcset=\"https:\/\/myallcodes.in\/wp-content\/uploads\/2024\/04\/get-info-1.jpg 509w, https:\/\/myallcodes.in\/wp-content\/uploads\/2024\/04\/get-info-1-209x300.jpg 209w\" sizes=\"auto, (max-width: 509px) 100vw, 509px\" \/><\/figure>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p># Sometimes we need to get the host name of PDC then we can use this code\/script # To get the all groups and members details from Active directory using Power Shell script and output will be store in csv file # PowerShell command to get the OS and Hardware complete details<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-33","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/pages\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":6,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/pages\/33\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/pages\/33\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}