Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CLS
  2. #Gives the user access to the loop less then 1 an higher then 20.
  3.   do {
  4.  
  5.    [int]$userMenuChoice = 0
  6.     while ( $userMenuChoice -lt 1 -or $userMenuChoice -gt 26) {
  7. #writes down all the different options
  8.  
  9.     write-host `t""`t
  10.     write-host -ForegroundColor 'Green' `t"*  Troubleshooting tools"`t
  11.     write-host -ForegroundColor 'Green' ------------------------------------
  12.     write-host -ForegroundColor 'Yellow'`t"1.  Ping your own host"
  13.     write-host -ForegroundColor "Yellow"`t"2.  Ping Google DNS"
  14.     write-host -ForegroundColor "Yellow"`t"3.  Test-connection"
  15.     write-host -ForegroundColor "Yellow"`t"4.  Test-netconnection on port"
  16.     write-host -ForegroundColor "Yellow"`t"5.  Traceroute"
  17.     write-host -ForegroundColor "Yellow"`t"6.  ARP network information"
  18.     write-host -ForegroundColor "Yellow"`t"7.  NSlookup"
  19.     write-host -ForegroundColor 'Yellow'`t"8.  Netstat"
  20.     write-host -ForegroundColor "Yellow"`t"9.  Restart RDP services"
  21.     write-host -ForegroundColor 'Green' `t""`t
  22.     write-host -ForegroundColor 'Green' `t"**` Change configuration"`t
  23.     write-host -ForegroundColor 'Green'  ------------------------------------
  24.     write-host -ForegroundColor 'Yellow'`t"10. Start sconfig"
  25.     write-host -ForegroundColor 'Yellow'`t"11. Disable or enable firewall"
  26.     write-host -ForegroundColor 'Yellow'`t"12. Enable remote powershell"  
  27.     write-host -ForegroundColor 'Green' `t""`t
  28.     write-host -ForegroundColor 'Green' `t"***`Install Windows roles and sysinfo"`t
  29.     write-host -ForegroundColor 'Green' -------------------------------------
  30.     write-host -ForegroundColor "Yellow"`t"13. Install or remove Server Role"
  31.     write-host -ForegroundColor "Yellow"`t"14. Show running services"
  32.     write-host -ForegroundColor 'Yellow'`t"15. System services information"
  33.     write-host -ForegroundColor "Yellow"`t"16. Show System information with expert"
  34.     write-host -ForegroundColor "Yellow"`t"17. Fix Sharepoint IIS problem"
  35.     write-host -ForegroundColor "Yellow"`t"18. Run SFC /scannow"
  36.     write-host -ForegroundColor "Yellow"`t"19. Restore the health with DISM"
  37.     write-host -ForegroundColor "Yellow"`t"20. Show stopped services"
  38.     write-host -ForegroundColor "Yellow"`t"21. Start or stop a service"
  39.     write-host -ForegroundColor "Yellow"`t"22. Boot into Different boot state"
  40.     write-host `t""`t
  41.     write-host -ForegroundColor 'Green' `t"****`Import active directory configuration"`t
  42.     write-host -ForegroundColor 'Green' -------------------------------------
  43.     write-host -ForegroundColor "Yellow"`t"23. Import Users into active directory"
  44.     write-host -ForegroundColor "Yellow"`t"24. Import Groups"
  45.     write-host -ForegroundColor 'Yellow'`t"25. Import Grouppolicy"
  46.     write-host -ForegroundColor "Yellow"`t"26. Import OU structure"
  47.     write-host -ForegroundColor "Yellow"`t"27. Import Folder structure on D drive"
  48.     write-host -ForegroundColor "Yellow"`t"28. Import structure,shares and permissions"
  49.     write-host `t""`t
  50.     write-host -ForegroundColor 'Green' `t"*****`Export active directory configuration"`t
  51.     write-host -ForegroundColor 'Green' -------------------------------------
  52.     write-host -ForegroundColor "Yellow"`t"29. Export Users into CSV File"
  53.     write-host -ForegroundColor "Yellow"`t"30. Export Group"
  54.     write-host -ForegroundColor "Yellow"`t"31. Export GroupPolicy"
  55.     write-host -ForegroundColor "Yellow"`t"32. Export OU structure"
  56.     write-host -ForegroundColor "Yellow"`t"33. Export Folder structure Shares, D drive"
  57.     write-host -ForegroundColor "Yellow"`t"34. Export file structure,shares and permissions"
  58.  
  59.    [int]$userMenuChoice =  Read-Host -Prompt ` "
  60.  
  61.   Type your option or press enter to exit"
  62.    
  63. #excecutes the commands given by the user
  64.      
  65.     switch ($userMenuChoice)   {
  66.  
  67. #Ping module
  68.  
  69.       '1' {
  70.  
  71.               $Server = Read-Host -Prompt 'hostname'
  72.               $value = Read-Host -Prompt 'function'
  73.               ping $Server $value
  74. #Ping google
  75.  
  76.         }
  77.          '2'{
  78.              test-connection 8.8.8.8,8.8.4.4
  79.         }
  80. #test-netconnnection  
  81.      
  82.          '3'{
  83.             $Server = Read-Host -Prompt 'Hostname'
  84.             Test-Connection $server
  85.         }
  86. #test-netconection using port
  87.  
  88.          '4'{
  89.             $Server = Read-Host -Prompt 'Hostname'
  90.             $port = Read-Host -Prompt 'port'
  91.             Test-netconnection $server -port $port
  92.         }
  93.  
  94. #Tracert host module
  95.  
  96.          '5'{
  97.             $Server = Read-Host -Prompt 'Hostname'
  98.             Tracert $server
  99.         }
  100.  
  101. #NSlookup on host
  102.  
  103.          '6'{
  104.             $Server = Read-Host -Prompt 'Hostname'
  105.             NSlookup $server
  106.         }
  107.  
  108. #ARP on localhost
  109.          '7'{
  110.             $function1 =o Read-Host -Prompt 'function Example -A,-AB'
  111.             arp $function1
  112.         }
  113. #Netstat
  114.          '8'{        
  115.             $function2 = Read-Host -Prompt 'function Example -A,-AB'
  116.             netstat $function2
  117.         }
  118. #ipconfig
  119.          '8'{        
  120.             $function3 = Read-Host -Prompt 'function Example /all /release /fushdns, /registerdns, ipconfig /allcompartments /all'
  121.             Ipconfig $function3
  122.         }
  123. #restart-rdp services
  124.          '9'{
  125.          write-host -ForegroundColor Green "Trying to restart RDP services"
  126.             Function Restart-RdpServices {
  127.  
  128.             param([string]$ComputerName = $env:computerName)
  129.             Get-Service -ComputerName $CompaterName -Name 'Remote Desktop Services UserMode Port Redirector' | Stop-Service -Force -Verbose
  130.             Get-Service -ComputerName $ComputerName -Name 'TermService' | Stop-Service -Force -Verbose
  131.             Get-Service -ComputerName $ComputerName -Name 'TermService' | Start-Service -Verbose
  132.             Get-Service -ComputerName $ComputerName -Name 'Remote Desktop Services UserMode Port Redirector' | Start-Service -Verbose
  133.            }
  134.             write-host -ForegroundColor Green "RDP has been restarted"
  135.              [int]$userMenuChoice = 0
  136.             }
  137.  
  138. #Start Sconfig
  139.  
  140.         '10'{
  141.                write-host -ForegroundColor Green "Launching Sconfig"
  142.               start-process powershell -ArgumentList "-noexit -command sconfig"
  143.         }
  144. #change Firwall settings
  145.  
  146.         '11'{
  147.               $on  = 'True'
  148.               $off = 'False'
  149.               write-host -ForegroundColor Green "Change Firewalls settings"
  150.               $option = Read-Host -Prompt 'True or False'
  151.  
  152.               Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled $option
  153.               write-host -ForegroundColor Green "The firewall has changed to your setting to $option"
  154.         }
  155. #change Remote powershell command
  156.  
  157.         '12'{
  158.               Enable-PSRemoting -SkipNetworkProfileCheck -Force
  159.               write-host -ForegroundColor Green "Powershell Remoting is now enabled"
  160.          }
  161. #Start switch 1 for roles
  162.        
  163.         '13'{
  164.                        [int]$userMenuChoice1 = 0
  165.                 while ( $userMenuChoice1 -lt 1 -or $userMenuChoice1 -gt 26) {
  166.                 write-host `t""`t
  167.                 write-host  -ForegroundColor 'Green'`t"Install or or Remove windows services"`t
  168.                 write-host `t""`t
  169.                 write-host -ForegroundColor 'Yellow'`t"1.  Install Remote desktop services"
  170.                 write-host -ForegroundColor "Yellow"`t"2.  DHCP COnfiguruation with options"
  171.                 write-host -ForegroundColor "Yellow"`t"3.  Install RSAT for windows 10"
  172.                 write-host -ForegroundColor "Yellow"`t"4.  Install Active directory"
  173.                 write-host -ForegroundColor "Yellow"`t"5.  Install Hyper-V hypervisor"
  174.                 write-host -ForegroundColor "Yellow"`t"6.  Install Remote access"
  175.                 write-host -ForegroundColor "Yellow"`t"7.  Remove windows Defender "
  176.                 write-host -ForegroundColor "Yellow"`t"7.  Remove SMBV1 for security"
  177.                 write-host `t""`t
  178.    
  179.                 [int]$userMenuChoice1 =  Read-Host -Prompt ` "
  180.               Type your option or press enter to exit"
  181.    
  182. #excecutes the commands given by the user
  183.      
  184.             switch ($userMenuChoice1)
  185.             {
  186.                 #Install Remote desktop services
  187.         '1'{
  188.                 write-host -ForegroundColor Green -confirm  "RDP server gets installed"
  189.                 Add-WindowsFeature –Name RDS-RD-Server –IncludeAllSubFeature -Restart
  190.                
  191.                 }
  192.                #DHCPv
  193.         '2'{
  194.                write-host -ForegroundColor Green  "DHCP server gets installed"
  195.                Install-WindowsFeature -Confirm  Install-WindowsFeature DHCP  -IncludeManagementTools
  196.                $computer = $env:computername
  197.                $dns =Read-Host -Prompt 'DNS name'
  198.                $ipAddress =Read-Host  -Prompt 'IPAdress'
  199.                Add-DhcpServerInDC -DnsName $dns -IPAddress $ipAddress
  200.                Get-DhcpServerInDC
  201.                Set-ItemProperty –Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\Roles\12 –Name ConfigurationState –Value 2
  202.                $name = Read-Host  -Prompt 'Name of your scope'
  203.                $scope =  -Prompt 'scope ID'
  204.                $start = -Prompt 'StartRange'
  205.                $end = -Prompt 'EndRange'
  206.                $name = -Prompt 'Name of your scope'
  207.                $subnet = -Prompt 'Enter your subnet'
  208.                $dnsserver = -Prompt 'Enter your subnet'
  209.        
  210.                Add-DhcpServerv4Scope -name "$name" -StartRange $start -EndRange $end -SubnetMask $subnet -State Active`
  211.                Set-DhcpServerv4OptionValue -OptionID 3 -Value $start  -ScopeID $scope -ComputerName $computer$dns`
  212.                Set-DhcpServerv4OptionValue -DnsDomain $dns -DnsServer $dnsserver
  213.                }
  214.  
  215.                 #Install RSAT on win10
  216.         '3'{
  217.                 write-host -ForegroundColor Green "RSAT server gets installed"
  218.  
  219.                 $web = Invoke-WebRequest https://www.microsoft.com/en-us/download/confirmation.aspx?id=45520
  220.  
  221.                 $MachineOS= (Get-WmiObject Win32_OperatingSystem).Name
  222.  
  223.                 #Check for Windows Server 2012 R2
  224.                 IF($MachineOS -like "*Microsoft Windows Server*") {
  225.                     Add-WindowsFeature -Confirm RSAT-AD-PowerShell
  226.                     Break}
  227.  
  228.                         IF ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64"){
  229.                             Write-host "x64 Detected" -foregroundcolor yellow
  230.                             $Link=(($web.AllElements |where class -eq "multifile-failover-url").innerhtml[0].split(" ")|select-string href).tostring().replace("href=","").trim('"')
  231.                             }ELSE{
  232.                             Write-host "x86 Detected" -forgroundcolor yellow
  233.                             $Link=(($web.AllElements |where class -eq "multifile-failover-url").innerhtml[1].split(" ")|select-string href).tostring().replace("href=","").trim('"')
  234.                             }
  235.  
  236.                 $DLPath= ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])
  237.  
  238.                 Write-Host "Downloading RSAT MSU file" -foregroundcolor yellow
  239.                 Start-BitsTransfer -Source $Link -Destination $DLPath
  240.  
  241.                 $Authenticatefile=Get-AuthenticodeSignature $DLPath
  242.  
  243.  
  244.                 $WusaArguments = $DLPath + " /quiet"
  245.                 if($Authenticatefile.status -ne "valid") {write-host "Can't confirm download, exiting";break}
  246.                 Write-host "Installing RSAT for Windows 10 - please wait" -foregroundcolor yellow
  247.                 Start-Process -FilePath "C:\Windows\System32\wusa.exe" -ArgumentList $WusaArguments -Wait    
  248.                 }
  249.  
  250.         '4'{ # install active directory
  251.                 Import Server-Manager
  252.                 write-host -ForegroundColor Green "Install active directory"
  253.                 install-windowsfeature AD-Domain-Services
  254.                 Import-Module ADDSDeployment
  255.                 Install-ADDSForest
  256.                 }
  257.         '5'{ # install Hyper V
  258.                 write-host -ForegroundColor Green "Hyper-V"
  259.                 Add-WindowsFeature –Name Hyper-V -IncludeAllSubFeature -IncludeManagementTools
  260.                 }
  261.  
  262.         '6'{ # install Remote access
  263.                 Install-WindowsFeature RemoteAccess -IncludeManagementTools
  264.                 }
  265.  
  266.  
  267.          '7' {# install Remote access
  268.             write-host -ForegroundColor Green -confirm  "Install Remote access VPN"
  269.             Install-WindowsFeature RemoteAccess -IncludeManagementTools -confirm
  270.         }
  271.  
  272.          '8'{ #remove windows defender
  273.                     Remove-WindowsFeature Windows-Defender, Windows-Defender-GUI
  274.                     }
  275.          '9'{ # Remove SMBV1
  276.                     Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol #Remove SMBv1 Client Support
  277.                     }
  278.  
  279.         '10'{ #Install windows backup
  280.                     Add-WindowsFeature Windows-Server-Backup
  281.                }
  282.         '11'{
  283.  
  284.                }
  285.            }
  286.           }
  287.          }        
  288.        
  289.         '14'{
  290.            write-host -ForegroundColor Green "Running processes are getting loaded. Press enter"
  291.  
  292.                 while(1) {ps | sort -desc cpu | select -first 30; sleep -seconds 60; cls;
  293.             write-host "Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName";
  294.             write-host "-------  ------    -----      ----- -----   ------     -- -----------"}
  295.                     }
  296. #Start Services.msc
  297.  
  298.         '15'{
  299.         write-host -ForegroundColor Green "System services are getting loaded......."
  300. service
  301. Get-WmiObject win32_service |  Format-Table -Property Exit,CodeName,ProcessId,StartMode,State,Status |
  302.  where { $_.Caption -notmatch "Windows" -and $_.PathName -notmatch "Windows" -and $_.PathName -notmatch "policyhost.exe" }
  303. `
  304.   (sleep -seconds 2)}
  305.  
  306. #get computer information
  307.  
  308.           '16'{
  309.  
  310.           write-host -ForegroundColor Green -confirm  "Gathering system information"
  311.                  function Get-ComputerInformation {
  312.             [cmdletbinding()]
  313.             param(
  314.                 [Parameter()]
  315.                 [string]
  316.                 $computerName
  317.             )
  318.             if (!$computerName) {
  319.  
  320.                 $osVer          = Get-CimInstance Win32_OperatingSystem | Select-Object  Caption | ForEach-Object { $_.Caption }
  321.                 $installDate    = Get-CimInstance Win32_OperatingSystem | Select-Object  InstallDate | ForEach-Object { $_.InstallDate }
  322.                 $servicePackVer = Get-CimInstance Win32_OperatingSystem | Select-Object  ServicePackMajorVersion | ForEach-Object { $_.ServicePackMajorVersion }
  323.                 $osArch         = Get-CimInstance Win32_OperatingSystem | Select-Object  OSArchitecture | ForEach-Object { $_.OSArchitecture }
  324.                 $bootDevice     = Get-CimInstance Win32_OperatingSystem | Select-Object  BootDevice | ForEach-Object { $_.BootDevice }
  325.                 $buildNumber    = Get-CimInstance Win32_OperatingSystem | Select-Object  BuildNumber | ForEach-Object { $_.BuildNumber }
  326.                 $osName         = Get-CimInstance Win32_OperatingSystem | Select-Object  CSName | ForEach-Object { $_.CSName }
  327.                 $hostName       = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .
  328.  
  329.             } else {
  330.             }
  331.                 $reportObject = [PSCustomObject]@{
  332.        
  333.                 'OS Version'           = $osVer
  334.                 'Install Date'         = $installDate
  335.                 'Service Pack Version' = $servicePackVer
  336.                 'OS Architecture'      = $osArch
  337.                 'Boot Device'          = $bootDevice
  338.                 'Build Number'         = $buildNumber
  339.                 'Host Name'            = $hostName
  340.  
  341.                     }
  342.                                 return $reportObject
  343.                 }
  344.  
  345.                 $compInfo = Get-ComputerInformation
  346.                 $compInfo | Format-List
  347.  
  348.                 Write-Host `n"Detailed Networking Information:"`n
  349.                 Write-Host ($compInfo.'Host Name' | Out-String)
  350.  
  351.                 $reportPath = 'C:\reports'
  352.  
  353.                 if (test-path $reportPath)
  354.                 {  
  355.                     Write-Host "Folder found!"
  356.                 }
  357.                 else
  358.                 {
  359.                     Write-Host "Folder NOT FOUND!"
  360.                     write-host "Folder has been created"
  361.                    
  362.                     New-Item -ItemType directory -Path $reportPath
  363.                 }
  364.  
  365.                 $compInfo | Export-CSV -Delimiter ";" "$reportPath\system report.csv" -NoTypeInformation -Encoding UTF8
  366.    
  367.                     }
  368. #fix issue on Share Point IIS
  369.  
  370.            '17'{
  371.             write-host -ForegroundColor Green "applying hot fix for Sharepoint"
  372.                 Copy-Item -Path "$($ENV:SystemRoot)\System32\ServerManager.exe" `
  373.                     -Destination "$($ENV:SystemRoot)\System32\ServerManagerCmd.exe" -Force
  374.  
  375.                 Add-WindowsFeature NET-WCF-HTTP-Activation45,NET-WCF-TCP-Activation45,NET-WCF-Pipe-Activation45
  376.                 Add-WindowsFeature Net-Framework-Features,Web-Server,Web-WebServer, `
  377.                     Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing, `
  378.                     Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext, `
  379.                     Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor, `
  380.                     Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering, `
  381.                     Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression, `
  382.                     Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server, `
  383.                     AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation, `
  384.                     AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model, `
  385.                     WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation, `
  386.                     Server-Media-Foundation,Xps-Viewer
  387.                               }
  388.             #System file Recovery
  389.  
  390.             '18'{
  391.                     write-host -ForegroundColor Green "Restore system health"
  392.                     SFC /SCANNOW
  393.                     }
  394.             #Powershell system recovery
  395.  
  396.             '19'{
  397.                     write-host -ForegroundColor Green "Restore system health"
  398.                     DISM /ONLINE /CLEANUP-IMAGE /RESTOREHEALTH
  399.                     }
  400.  
  401.             #show stopped services on localhost
  402.  
  403.             '20'{   Get-WmiObject -Class Win32_Service | Select-Object Name,State,StartMode  | Where-Object {$_.State -ne "Running" -and $_.StartMode -eq "Auto" } | Format-Table -Property Name,State,StartMode
  404.             }
  405.  
  406.             '21'{
  407.             #Enable or Disable processes
  408.  
  409.                     $choice = Read-Host -Prompt 'Start,Stop,Restart'
  410.                     $Servicename = Read-Host -Prompt 'Service name'
  411.  
  412.                     If ( $choice -eq '') {write-host -ForegroundColor "Red" "Invalid request"}
  413.                     If ( $choice -eq 'Start') {
  414.  
  415.                     Get-Service -Name  $Servicename | start-service -Verbose
  416.                     }
  417.                     If ( $choice -eq 'Stop') {
  418.  
  419.                     Get-Service -Name  $Servicename | stop-service -Force -Verbose
  420.                     }
  421.                     If ( $choice -eq 'Restart') {
  422.  
  423.                     Get-Service -Name  $Servicename | stop-service -Force -Verbose
  424.                     Get-Service -Name  $Servicename | start-service -Verbose
  425.                     write-host -ForegroundColor Green -confirm  "$service has been $choice"
  426.                  }
  427.               }
  428.             '22'{      
  429.            
  430.   #write the options on powershell screen and start of switch 2
  431.  
  432.                        [int]$userMenuChoice2 = 0
  433.                         while ( $userMenuChoice2 -lt 1 -or $userMenuChoice2 -gt 26) {
  434.                         write-host `t""`t
  435.                         write-host  -ForegroundColor 'Green'`t"Change Boot"`t
  436.                         write-host `t""`t
  437.                         write-host -ForegroundColor 'Yellow'`t"1.  BCDEdit /bootdebug"
  438.                         write-host -ForegroundColor "Yellow"`t"2.  BCDEdit /dbgsettings"
  439.                         write-host -ForegroundColor "Yellow"`t"3.  BCDEdit /debug"
  440.                         write-host -ForegroundColor "Yellow"`t"4.  BCDEdit /deletevalue"
  441.                         write-host -ForegroundColor "Yellow"`t"5.  BCDEdit /emssettings"
  442.                         write-host -ForegroundColor "Yellow"`t"6.  BCDEdit /set"
  443.                         write-host -ForegroundColor "Yellow"`t"7.  BCDEdit /set safeboot "
  444.                         write-host -ForegroundColor "Yellow"`t"7.  BCDEdit /DSRM recovery mode "
  445.                         write-host `t""`t
  446.    
  447.                             #switch number 2 option menu with switching
  448.                        
  449.                             [int]$userMenuChoice2 =  Read-Host -Prompt ` "
  450.                            Type your option or press enter to exit"
  451.  
  452.                             #excecutes the commands given by the user
  453.                             switch ($userMenuChoice2)
  454.                             {  
  455.                                  '1' {
  456.                                  BCDEdit /bootdebug
  457.                                   restart-computer -Confirm
  458.                                 }
  459.                                  '2' {
  460.  
  461.                                  BCDEdit /dbgsettings
  462.                                  restart-computer -Confirm
  463.                                 }
  464.                                  '3' {
  465.                                  BCDEdit /debug
  466.                                  restart-computer -Confirm
  467.                                 }
  468.                                  '4' {
  469.                                  BCDEdit /deletevalue
  470.                                  restart-computer -Confirm
  471.                                 }
  472.                                 '5' {
  473.  
  474.  
  475.                                  BCDEdit /emssettings
  476.                                  restart-computer -Confirm
  477.                                 }
  478.                                  '6' {
  479.                                  BCDEdit /set
  480.                                  restart-computer -Confirm
  481.                                 }
  482.                                 '7' {
  483.  
  484.                                   BCDEdit /set safeboot
  485.                                   restart-computer -Confirm
  486.                                 }
  487.  
  488.                                  '8' {
  489.                                   BCDEdit /set safeboot dsrepair
  490.                                   restart-computer -Confirm
  491.                                 }
  492.                                
  493.                                 #end switch 2
  494.                             }
  495.                          
  496.  
  497.                         }
  498.             }
  499.          
  500.             '23'{
  501.  
  502. #create active directory users
  503.  
  504.                     $locationuser = Read-Host -Prompt 'Put the name of file here'
  505.  
  506.  
  507.                     $users = Import-Csv -delimiter ";" -path $locationuser.csv
  508.  
  509.                     foreach($user in $users)
  510.                     {
  511.                     $fullname = $user.firstname + " " + $User.middlename + $user.lastname
  512.                     $firstname = $user.firstname
  513.                     $lastname = $user.lastname
  514.                     $domain = "@mocati.eu"
  515.                     $upn = $user.firstname + $User.middlename + $user.lastname + $domain
  516.                     $ou = $user.ou
  517.                     $password = "Welkom01!"
  518.                     $setpassword = ConvertTo-SecureString $password -AsPlainText -Force
  519.                     $Usermiddlename = $User.middlename
  520.                     $first,$last = ($firstname.toUpper()).Split(" ")
  521.                     $letter = $first[0]
  522.                     $username = $letter + $User.middlename + $lastname
  523.  
  524.                     New-ADUser -Name $username -displayname $fullname `
  525.                     -GivenName $firstname -surname $lastname `
  526.                     -SamAccountName $lastname `
  527.                     -UserPrincipalName $upn `
  528.                     -AccountPassword $setpassword -Enabled $true -PassThru `
  529.                     -ChangePasswordAtLogon $false
  530.  
  531. }
  532.  
  533.               }
  534.  
  535.             '24'{  
  536.                     $locatiegroepen = Read-Host -Prompt 'Put the name of file here'
  537.                     $csv = Import-Csv -delimiter ";" -Path "C:\scripts\$locatiegroepen.csv"
  538.  
  539.                     ForEach ($item In $csv)
  540.                         {
  541.                             $create_group = New-ADGroup -Name $item.GroupName -GroupCategory $item.GroupCategory -groupScope $item.GroupScope
  542.                             Write-Host -ForegroundColor Green "Group $($item.GroupName) created!"
  543.                         }
  544.  
  545.             }
  546.             '25'{  
  547.  
  548.                   write-host "feature not here yet"
  549.  
  550.             }
  551.             '26'{  
  552.  
  553.  
  554.                     #OU script
  555.                     $oulocation = Read-Host -Prompt 'Put the name of file here'
  556.  
  557.                     $listOU=Import-Csv -delimiter ";" -Path "C:\scripts\$oulocation.csv"
  558.                     ForEach($OU in $listOU){
  559.  
  560.                     try{
  561.                     #Get Name and Path from the source file
  562.                     $OUName = $OU.Name
  563.                     $OUPath = $OU.Path
  564.  
  565.                     #Display the name and path of the new OU
  566.                     Write-Host -Foregroundcolor Yellow $OUName $OUPath
  567.  
  568.                     #Create OU
  569.                     New-ADOrganizationalUnit -Name "$OUName" -Path "$OUPath"
  570.  
  571.                     #Display confirmation
  572.                     Write-Host -ForegroundColor Green "OU $OUName created"
  573.                     }catch{
  574.  
  575.                     Write-Host $error[0].Exception.Message
  576.                     }
  577.  
  578.                     }-Path "$alleOU" -ProtectedFromAccidentalDeletion $false
  579.  
  580.             }          
  581.             '27'{
  582.                 $locationfolder = Read-Host -Prompt 'Put the location C:\*\something'
  583.                 $csvfilelocation = Read-Host -Prompt 'Put the location of CSV file C:\*\something.csv'
  584.                 Set-Location "$locationfolder"
  585.                 $Folders = Import-Csv $csvfilelocation
  586.                 ForEach ($Folder in $Folders) {
  587.                 New-Item $Folder.Name -type directory
  588. }
  589.             }
  590.             '28'{  
  591.              
  592.  
  593.                 #needs changes
  594.                 write-host "feature not programmed yet"
  595.  
  596.             }
  597.             '29'{  
  598.             Get-ADUser -Filter 'Company -like "Alpha*"' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8
  599.             }
  600.          
  601.             '30'{   #// Start of script
  602.                     #// Get year and month for csv export file
  603.                     $DateTime = Get-Date -f "yyyy-MM"
  604.  
  605.                     #// Set CSV file name
  606.                     $CSVFile = "C:\AD_Groups"+$DateTime+".csv"
  607.  
  608.                     #// Create emy array for CSV data
  609.                     $CSVOutput = @()
  610.  
  611.                     #// Get all AD groups in the domain
  612.                     $ADGroups = Get-ADGroup -Filter *
  613.  
  614.                     #// Set progress bar variables
  615.                     $i=0
  616.                     $tot = $ADGroups.count
  617.  
  618.                     foreach ($ADGroup in $ADGroups) {
  619.                         #// Set up progress bar
  620.                         $i++
  621.                         $status = "{0:N0}" -f ($i / $tot * 100)
  622.                         Write-Progress -Activity "Exporting AD Groups" -status "Processing Group $i of $tot : $status% Completed" -PercentComplete ($i / $tot * 100)
  623.  
  624.                         #// Ensure Members variable is empty
  625.                         $Members = ""
  626.  
  627.                         #// Get group members which are also groups and add to string
  628.                         $MembersArr = Get-ADGroup -filter {Name -eq $ADGroup.Name} | Get-ADGroupMember |  select Name
  629.                         if ($MembersArr) {
  630.                             foreach ($Member in $MembersArr) {
  631.                                 $Members = $Members + "," + $Member.Name
  632.                             }
  633.                             $Members = $Members.Substring(1,($Members.Length) -1)
  634.                         }
  635.  
  636.                         #// Set up hash table and add values
  637.                         $HashTab = $NULL
  638.                         $HashTab = [ordered]@{
  639.                             "Name" = $ADGroup.Name
  640.                             "Category" = $ADGroup.GroupCategory
  641.                             "Scope" = $ADGroup.GroupScope
  642.                             "Members" = $Members
  643.                         }
  644.  
  645.                         #// Add hash table to CSV data array
  646.                         $CSVOutput += New-Object PSObject -Property $HashTab
  647.                     }
  648.  
  649.                     #// Export to CSV files
  650.                     $CSVOutput | Sort-Object Name | Export-Csv $CSVFile -NoTypeInformation
  651.  
  652.                     #// End of script
  653.             }
  654.             '31'{  
  655.                     Import-Module ActiveDirectory
  656.                     Import-Module GroupPolicy
  657.                     $dc = Get-ADDomainController -Discover -Service PrimaryDC
  658.                     Get-GPOReport -All -Domain enterprise.com -Server $dc -ReportType HTML -Path C:\Temp\GPOReportsAll.html
  659.             }
  660.             '32'{  
  661.                     import-module activedirectory
  662.                     Get-ADOrganizationalUnit -filter * | select Name,DistinguishedName | Export-csv -path C:\ADOrganizationalUnitsexport.csv -NoTypeInformation
  663.             }
  664.             '33'{
  665.  
  666.                     $FolderPath = dir -Directory -Path "\\fs1\Shared" -Recurse -Force
  667.                     $Report = @()
  668.                     Foreach ($Folder in $FolderPath) {
  669.                         $Acl = Get-Acl -Path $Folder.FullName
  670.                         foreach ($Access in $acl.Access)
  671.                             {
  672.                                 $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
  673.                    Group or
  674.                    User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
  675.                                 $Report += New-Object -TypeName PSObject -Property $Properties
  676.                             }
  677.                     }
  678.                     $Report | Export-Csv -path "C:\data\FolderPermissions.csv"
  679.             }
  680.            
  681.  
  682.             '34'{  
  683.                     $FolderPath = dir -Directory -Path "\\fs1\Shared" -Recurse -Force
  684.                     $Report = @()
  685.                     Foreach ($Folder in $FolderPath) {
  686.                         $Acl = Get-Acl -Path $Folder.FullName
  687.                         foreach ($Access in $acl.Access)
  688.                             {
  689.                                 $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
  690.                    Group or
  691.                    User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
  692.                                 $Report += New-Object -TypeName PSObject -Property $Properties
  693.                             }
  694.                     }
  695.                     $Report | Export-Csv -path "C:\data\FolderPermissions.csv"
  696.             }          
  697.            
  698.  
  699.             #end primary switch {}
  700.            }                
  701.          }                                        
  702.         }  
  703.        
  704.  while ($userMenuChoice -ne 5 )
  705.  
  706.              #extra option Clear-Item WSMan:\localhost\Client\TrustedHosts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement