script
4 TopicsPowerShell Novice: Script Timeout #WSUS
Hi I'm an idiot. Have to say this at the beginning so you are ready to help a moron understand what is happening!!! And in plain English, or crayon...... I'm trying to schedule a PowerShell script to clean up my WSUS which is proving to be a pain to keep on top of.......little bit of research and I find the following basic script which appears to do what I need, however I get a red warning that this basically times out and then fails in its task. Is my script too basic and I am expecting too much, or can the time frame be increased to allow it to do what it needs to do?! I don't want to pay for the infamous AdamJ script and had hoped WSUS would be developed further by now to accommodate such cleaning tasks....but hey ho! Any help would be most welcome...thanks!! Get-Date >> E:\WSUS_Logs\WSUS_Decline.txt Get-WsusServer | Invoke-WsusServerCleanup -DeclineExpiredUpdates -DeclineSupersededUpdates >>E:\WSUS_Logs\WSUS_Decline.txt and a second script for the following Get-Date >> E:\WSUS_Logs\WSUS_Cleanup.txt Get-WsusServer | Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles >>E:\WSUS_Logs\WSUS_Cleanup.txt3KViews0likes7CommentsAutomating OneNote text with format to new Outlook message
Hello, I’m getting into PS, I’d like to automate basic processes on my own PC to start. There’s a constant process I do day in and day out, wanted to eliminate all the clicking, copying, pasting, typing and automate it. Taking texts in its format from OneNote, to opening a new Outlook message, pasting the text in the same format into the body of the new message. So all I’d have to do is fill in the email address and subject then click send.988Views0likes2CommentsHaving trouble moving multiple folders up a level
Hi all, I have a requirement to change a file structure for a client. Basically they want all files within an "FYxx" folder to be moved one level up while maintaining the folder structure. I developed a script to do this for one specified folder but now I want to expand that to all folders in the directory. This is the original script that works using one folder: # Define the source directory $source = "C:\SP\AGA" # Get all the FY folders in the source directory $fyFolders = Get-ChildItem -Path $source -Directory | Where-Object { $_.Name -like "FY*" } # Loop through each FY folder foreach ($fyFolder in $fyFolders) { # Get all the subfolders in the FY folder $subfolders = Get-ChildItem -Path $fyFolder.FullName -Recurse -Directory # Get all the files in the FY folder $subfiles = Get-ChildItem -Path $fyFolder.FullName -Recurse -File # Combine the subfolders and files into one array $subitems = $subfolders + $subfiles # Loop through each subfolder and file foreach ($subitem in $subitems) { # Get the relative path to the subfolder or file $relativePath = $subitem.FullName.Substring($fyFolder.FullName.Length) # Move the subfolder or file to the parent folder Move-Item -LiteralPath $subitem.FullName -Destination ($fyFolder.Parent.FullName + $relativePath) } # Get the contents of the FY folder after all subfolders and files have been moved $contents = Get-ChildItem -Path $fyFolder.FullName # Check if the FY folder has no files if (!$contents.Where{ $_.PsIsContainer -eq $false }) { # Delete the FY folder if it has no files Remove-Item -Path $fyFolder.FullName -Recurse } } I then wanted to add a capability to scan the parent directory and use those results as the source. This is what I have but it doesn't actually do anything. It doesn't fail with an error it just does nothing: # Define the path to the parent folder $parentFolder = "C:\SP" # Get all subfolders in the parent folder $subFolders = Get-ChildItem -Path $parentFolder -Directory # Loop through each subfolder foreach ($subFolder in $subFolders) { # Get the source folder $source = $subFolder.FullName # Get all subfolders with "FY" in the name $fyFolders = Get-ChildItem -Path $source -Recurse | Where-Object { $_.PSIsContainer -and $_.Name -like "*FY*" } # Loop through each FY folder foreach ($fyFolder in $fyFolders) { # Get all items (files and subfolders) in the FY folder $items = Get-ChildItem -Path $fyFolder.FullName -Recurse -File -Directory # Move all items to the parent folder foreach ($item in $items) { $destination = Join-Path -Path $fyFolder.Parent.FullName -ChildPath $item.Name Move-Item -LiteralPath $item.FullName -Destination $destination } } # Delete all empty FY folders $emptyFyFolders = Get-ChildItem -Path $source -Recurse | Where-Object { $_.PSIsContainer -and $_.Name -like "*FY*" -and (!(Get-ChildItem -Path $_.FullName -Recurse)) } foreach ($emptyFyFolder in $emptyFyFolders) { Remove-Item -Path $emptyFyFolder.FullName -Force -Recurse } } Any idea where I am going wrong? Thanks, David1.6KViews0likes2CommentsPowershell and filtering results from cmdlest into CSVs
Hi everyone, I need to have a script that outputs a CSV list, to be used for a mail merge, with the last login and the alternative emails (and other useful info for the mail merge), so I can mass mail anyone that has not logged in yet. I have stumbled my way into creating a script, with lots of help and cobbled together from around the internet, now I am just missing a piece, which is to filter out users that have not logged in yet, as in have no data in the LastSignInDateTime field. This is the script: param($path="$PSScriptRoot\reports",$pwdnochangedindays = 480) cd $path Start-transcript $cohort = read-host "Enter cohort to audited" Connect-MgGraph -Scopes "Directory.ReadWrite.All", "Directory.AccessAsUser.All","User.Read.All","AuditLog.Read.All" Select-MgProfile -Name beta $MSGProps = @( 'id' 'displayName' 'CompanyName' 'State' 'OfficeLocation' 'department' 'signInActivity' 'userPrincipalName' 'userType' 'createdDateTime' 'accountEnabled' 'passwordPolicies' 'mail' 'lastPasswordChangeDateTime' 'OtherMails' ) $MSGSplat = @{ Filter = "userType eq 'Member' and AccountEnabled eq true and startsWith(State, '$cohort')" all = $true Property = $MSGProps } $MSGUser = Get-MgUser @MSGSplat $Results = Foreach ($SingleMSG in $MSGUser) { [pscustomobject]@{ Id = $SingleMSG.id DisplayName = $SingleMSG.displayName CompanyName = $SingleMSG.CompanyName State = $SingleMSG.State OfficeLocation = $SingleMSG.OfficeLocation Department = $SingleMSG.department UserPrinciple = $SingleMSG.userPrincipalName UserType = $SingleMSG.userType Created = $SingleMSG.createdDateTime Enabled = $SingleMSG.accountEnabled Mail = $SingleMSG.mail PasswordChange = $SingleMSG.lastPasswordChangeDateTime PasswordPolicy = $SingleMSG.passwordPolicies LastSignInDate = $SingleMSG.signInActivity.LastSignInDateTime LastNonInteractive = $SingleMSG.signInActivity.LastNonInteractiveSignInDateTime OtherMails = $SingleMSG | select-object -expand OtherMails } } $Results | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation write-host "Report can be found here $path" Stop-transcript # Based on chadmcox create-AADMGUserReport.ps1 # https://www.reddit.com/r/PowerShell/comments/vlrvca/expandproperty_csv_exporting_and_general_noobness/ # https://www.reddit.com/r/PowerShell/comments/vi8rcv/getting_a_list_of_all_users_last_login_status_and/ It produces a CSV like this: No idea how to do that, I have tried to add $results | where-object {$_.LastSignInDate -ne $null} | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation to the export oart of it , but no results from that. Any suggestions on how to get only people with no log-ins included?2.2KViews0likes9Comments