powershell 5.1
2 TopicsUnable to update help in MS PowerShell
Dear community, I have just started learning Microsoft PowerShell, so I apologize in advance in case my problem turns out to be too trivial. I have Windows 10 (Version 10.0.15063) installed on my virtual machine. PSVersion 5.1.15063.0 When trying to run Update-Help (in Administrator privilege) the process finished with multiple errors. PS C:\> Update-Help Update-Help : Failed to update Help for the module(s) "AppBackgroundTask, AppvClient, AssignedAccess, BitsTransfer, CimCmdlets, Defender, DnsClient, iSCSI, ISE, Microsoft.PowerShell.Archive, Microsoft.PowerShell.Core, Microsoft.PowerShell.Diagnostics, Microsoft.PowerShell.Host, Microsoft.PowerShell.LocalAccounts, Microsoft.PowerShell.Management, Microsoft.PowerShell.ODataUtils, Microsoft.PowerShell.Operation.Validation, Microsoft.PowerShell.Security, Microsoft.PowerShell.Utility, Microsoft.WSMan.Management, NetAdapter, NetEventPacketCapture, NetLbfo, NetNat, NetQos, NetSwitchTeam, NetTCPIP, PackageManagement, PowerShellGet, PSReadline, PSScheduledJob, PSWorkflow, PSWorkflowUtility, ScheduledTasks, Storage, TLS, UEV, WindowsDeveloper License, WindowsErrorReporting, WindowsSearch" with UI culture(s) {ru-RU}: Unable to connect to Help content. The server on which Help content is stored might not be available. Verify that the server is available, or wait until the server is back online, and then try the command again. At line:1 char:1 + Update-Help + ~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Update-Help], Exception + FullyQualifiedErrorId : UnableToConnect,Microsoft.PowerShell.Commands.UpdateHelpCommand Update-Help : Failed to update Help for the module(s) "PSDesiredStateConfiguration, VpnClient" with UI culture(s) {ru-RU}: Unable to retrieve the HelpInfo XML file for UI culture en-US. Make sure the HelpInfoUri property in the module manifest is valid or check your network connection and then try the command again. At line:1 char:1 + Update-Help + ~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [Update-Help], Exception + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand I would be extremely grateful if anyone could help me deal with this issue!592Views0likes2CommentsNeed a 5.1 script that will show the last login date, days since, and the SG's it belongs to
Here is my code so far. I don't know what I'm doing wrong, Can you please help me fix it. I plan to schedule it so it runs once per day on a server that has the proper modules installed for users that would like the information. Our account information is automatically deleted if we don't log in by so many days. I'm stuck and could really use the expertise of someone to give me some help. I've been trying for a week without asking for help but haven't been able to make it execute perfectly quite perfectly quiet yet. I'll be so happy once I'm able to get it working. If you can help me understand what I was doing wrong I'd appreciate that as well. At a later point, I'm going to add in SMTP information so it will mail out. I need to get a read-only server account for it but understand that I can do a runas with an account that has enough rights to run it. Being my first time here, I'm hoping it falls in with the guidelines. Thank you. Here is the desired output: Last login date for username1: 2022-10-15 10:23:41 Days since last login for username1: 25 Security groups for username1: - Group1 - Group2 - Group3 Last login date for username2: 2022-09-28 16:35:12 Days since last login for username2: 42 Security groups for username2: - Group2 - Group4 - Group5 Last login date for username1: 2022-11-02 09:45:18 Days since last login for username2: 7 Security groups for username3: - Group3 - Group6 Total usernames: 3 Here is my Code so far: # Import the Active Directory module Import-Module ActiveDirectory # Define the credentials for authentication $credentials = Get-Credential # Define the domain controller to query $domainController = "DC01.domain.com" # Define an array of usernames $usernames = @("username1", "username2", "username3") # Loop through the array of usernames foreach ($username in $usernames) { # Look up the user using the SamAccountName $user = Get-ADUser -Filter "SamAccountName -eq '${username}'" -Server $domainController -Credential $credentials if ($user) { # Get the last login date for the specified user from the specific domain controller $lastLogin = $user.LastLogonTimestamp # Get the security groups the user is a member of from the specific domain controller $userGroups = Get-ADUser -Identity $user.SamAccountName -Server $domainController -Credential $credentials | Get-ADGroup -Property Name | Select-Object -ExpandProperty Name # Convert the last login date to a readable format $lastLoginDate = [DateTime]::FromFileTime($lastLogin) # Calculate the number of days since the last login $daysSinceLastLogin = (Get-Date) - $lastLoginDate | Select-Object -ExpandProperty Days # Output the last login date and the number of days since the last login for each user Write-Host "Last login date for ${username}: ${lastLoginDate}" Write-Host "Days since last login for ${username}: ${daysSinceLastLogin}" # Output the security groups the user is a member of Write-Host "Security groups for ${username}:" foreach ($group in $userGroups) { Write-Host "- ${group}" } # Check if the number of days since the last login is greater than 30 if ($daysSinceLastLogin -gt 30) { Write-Host "WARNING: ${username} has not logged in for more than 30 days!" } } else { Write-Host "User ${username} not found in Active Directory." } } # Output the count of usernames Write-Host "Total usernames: $($usernames.Count)" Thank you2.3KViews0likes3Comments