Jump to content

eDecisions

Members
  • Posts

    56
  • Joined

  • Last visited

Everything posted by eDecisions

  1. Did this a long time ago... This one maps a drive letter to the server for the logged in user, you can work backwards to do anything, basically you have to create a task to make it happen that runs once on demand as the local user: $Taskname = "netuse" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $Taskname /RU $lastlogon /TR "c:\maplist.bat" start-sleep -s 1 New-Item c:\maplist.bat -ItemType "file" Set-Content c:\maplist.bat 'net use t: "\\twdserver\Shared\SERVER - Documents" /persistent:yes' schtasks /Run /TN $Taskname start-sleep -s 1 schtasks /delete /tn $Taskname /f
  2. Made one change this morning after testing, the log file is 50+ pages, I only really need to see the last 10 to 20lines of the log to see how things are going, added the -tail 20 to return the last 20 lines, tested this morning, I imagine next step would be to combine this for any/all longs I want and export to a text file and email as a daily summary. $dir = "C:\aktdata\quickbooks\Sync_Reports" $filter="*.txt" $latest = Get-ChildItem -Path $dir -Filter $filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1 $latest.name Get-Content $dir"\"$latest -tail 20
  3. Not my work, I took code form two locations and put them together to fit my needs, change the path to the path to your folder, change the filter to the file type to filter by, add as a script, run it, and then open your Last Executions to see the contents of the file. I was needing to check status of a log file on a server every so often, the log file name would change daily and be time stamped, this solved it for me. $dir = "C:\data\Sync_Reports" $filter="*.txt" $latest = Get-ChildItem -Path $dir -Filter $filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1 $latest.name Get-Content $dir"\"$latest
  4. sure I could do that as well and have a few customers doing that, I'm looking for a zero server touch however, and the ability to bring a new printer into a company and not have to touch the server, I have an onboarding task that does all my pc setup, so I want to add printers this way, little more up front work but once done I can get a call from any office, hay ken we just purchsed an HP xyx printer can you come set it up on my computer. CLICK done I've added 3 printers already I can do this with at any office, I've even managed to scan the network for the likely IP address of the printer, get its name and add a port by printer name. its clunky right now but heading in the correct direction.
  5. I did this for NINJA, try playing with the search key where the -match "your program" but be carefull $UninstallString = (Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\NinjaRMMAgent*).UninstallString sleep -seconds 2 if (!$UninstallString) { exit } sleep -seconds 2 $path = $UninstallString -replace "uninstall.exe", "" sleep -seconds 5 cd $path sleep -seconds 5 Start-Process -FilePath .\uninstall.exe -ArgumentList "--mode","unattended" sleep -seconds 40 $Uninstall2 = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "NinjaRMMAgent" } | Select-Object -Property UninstallString | foreach { $_.UninstallString } sleep -seconds 220 $Uninstall3 = $Uninstall2 -Replace "MsiExec.exe " , "" sleep -seconds 5 Start-Process -FilePath MSIExec.exe -ArgumentList $Uninstall3,"/quiet","/passive"
  6. I want to start a project, ADD-Printer via power shell, anyone want to help? Or you doing it alrady?
  7. I used a few times now and its about 90%, about 10% of the time my script fails to find the program, if anyone has any thoughts on what I missed please share.
  8. Darn, missed the fact that I was in session 0, ooops my bad, this should add to all active users. $Officepath = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe\Path") $Profiles = Get-ChildItem 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList' | ForEach-Object { $_.GetValue('ProfileImagePath') } foreach ($profile in $profiles -match "Users" -notmatch "spfarm" -notmatch "spsearch" -notmatch "TEMP" -notmatch "Classic"){ $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Profile\Desktop\Excel.lnk") $Shortcut.TargetPath = "$Officepath\Excel.exe" $Shortcut.Save() $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Profile\Desktop\Outlook.lnk") $Shortcut.TargetPath = "$Officepath\Outlook.exe" $Shortcut.Save() $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Profile\Desktop\Word.lnk") $Shortcut.TargetPath = "$Officepath\Winword.exe" $Shortcut.Save() }
  9. Great for onboarding new station, you can grab any other short cuts such as to shared rive, or network folders, the users C drive or the my documents folder as well, I just did the office apps. #By eDcisions $Officepath = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe\Path") $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Excel.lnk") $Shortcut.TargetPath = "$Officepath\Excel.exe" $Shortcut.Save() $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Outlook.lnk") $Shortcut.TargetPath = "$Officepath\Outlook.exe" $Shortcut.Save() $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Word.lnk") $Shortcut.TargetPath = "$Officepath\Winword.exe" $Shortcut.Save()
  10. What I started doing was creating Script Groups, hence every customer has their own set of scripts, however the point of this one was a little different, imagine you just want to map a drive for today between 2 computers at the office for the client, this works. If you'd like to get rid of the copy file first, conciser building the file first in powershell with the commands, and then call that file, and delete it after run. I did that with the "SHOW MAPPED DRIVES OF LOGGED IN USER" that I just posted, take a peek of how I wrote a local batch file and then ran it and deleted it. Script Group Specific customer 1 >Map drives Specific Customer 2 >Map Drivers Specific customer 3 >Map Drives
  11. I think thats the case, I submitted a request for info on the new feature and was told they were still working on it. So maybe this is just a pre-release, in its current form its not very usefull to me.
  12. Ok this guy will display the users mapped drive of the user thats logged into the pc as well as the status of the drive, disconnected, Ok, ect... Nice if you's setting up another pc remotely and you want to see what the shared drives on another users pc were so you can match them. #by eDecisions $Taskname = "netuse" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $Taskname /RU $lastlogon /TR "c:\maplist.bat" start-sleep -s 1 New-Item c:\maplist.bat -ItemType "file" Set-Content c:\maplist.bat 'net use >> c:\maplist.txt' schtasks /Run /TN $Taskname start-sleep -s 1 schtasks /delete /tn $Taskname /f get-content -path c:\maplist.txt del c:\maplist.txt del c:\maplist.bat
  13. its not expected to run as a stand alone script, I set this so I could run from the powershell instance, so you'd save the script above into a working folder on the client, could could call it anything you like with a ps1 Then from the power shell window you can type c:\mypath\myname.ps1 x: \\server\share were taking the %1 and %2 as $args0 and $args1, so you're completing the 2 items when you manually type the command in the powershell windows. hope that makes sense.
  14. way too much work, this adds a script by currently logged in use or last logged in user if system is logged off, note this is a powershell script, also I set its start time for before current time so it will only run if you manually start it but do what you will. #By eDecisions $TasknameStop = "ExplorerStop" $TasknameStart = "ExplorerStart" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe" SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" start-sleep -s 1 schtasks /Run /TN $TasknameStop start-sleep -s 1 schtasks /Run /TN $TasknameStart start-sleep -s 1 schtasks /delete /tn $TasknameStop /f schtasks /delete /tn $TasknameStart /f
  15. create a task, far easier, I use powershell, just add the command after the TR = Task Run #By eDecisions $TasknameStop = "ExplorerStop" $TasknameStart = "ExplorerStart" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe" SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" start-sleep -s 1 schtasks /Run /TN $TasknameStop start-sleep -s 1 schtasks /Run /TN $TasknameStart start-sleep -s 1 schtasks /delete /tn $TasknameStop /f schtasks /delete /tn $TasknameStart /f
  16. if you like to run a command as the user a quick way is to create and run a scheduled task setup as the logged in user and run it, see power shell example to start and restart explorer. #By eDecisions $TasknameStop = "ExplorerStop" $TasknameStart = "ExplorerStart" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe" SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" start-sleep -s 1 schtasks /Run /TN $TasknameStop start-sleep -s 1 schtasks /Run /TN $TasknameStart start-sleep -s 1 schtasks /delete /tn $TasknameStop /f schtasks /delete /tn $TasknameStart /f
  17. your missing the point of pulseway, why would you want to ever run a batch file located on your desktop, copy the batch file to pulseway and run it from there.
  18. I too played with them, I found as currently configured they are of no use to me, what I'm waiting for is a prompt at run time, you click your script and you get a prompt: enter drive lettr: or enter user name: or enter something, I'd find that a lot more usefull.Insert other media
  19. Script enables RDP if its disabled, and enables if its disabled. #By eDecisions $RDP = (Get-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server').fDenyTSConnections If ($RDP -eq 0) { Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value "1" } IF ($RDP -eq 1) { Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value "0" }
  20. This will stop and restart EXPLORER.EXE for the currently logged in user. #By eDecisions $TasknameStop = "ExplorerStop" $TasknameStart = "ExplorerStart" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe" SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" start-sleep -s 1 schtasks /Run /TN $TasknameStop start-sleep -s 1 schtasks /Run /TN $TasknameStart start-sleep -s 1 schtasks /delete /tn $TasknameStop /f schtasks /delete /tn $TasknameStart /f
  21. Be nice if you reference the Author rather than "I found this" I wrote it, thanks for the plug.
  22. This script changes the state of Hidden files, if hidden files are set to show this turns them off, if hidden files are set to hide this shows them. Comments? # This key contains all of the profiles on the machine (including non-user profiles) $profileList = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" # This key contains the path to the folder that contains all the profiles (typically c:\users) $profileFolder = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').ProfilesDirectory # This key contains the path to the default user profile (e.g. C:\Users\Default). This is **NOT** HKEY_USERS\.DEFAULT! # We don't do anything with it in this sample script, but it can be loaded and modified just like any other profile. $defaultFolder = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').Default # HKEY_USER key is not loaded into PowerShell by default and we'll need it, so we'll create new PSDrive to reference it. New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null $profileList | % { $profileKeys = Get-ItemProperty $_.PSPath $sid = $profileKeys.PSChildName $profilePath = $profileKeys.ProfileImagePath # This is an easy way to exclude profiles outside of the default USERS profile folder, e.g. LocalSystem. # You may or may not want to do this depending on your requirements. if ($profilePath -like "$($profileFolder)*") { # Check if the profile is already loaded. if (Get-ChildItem "HKU:\$sid" -ErrorAction SilentlyContinue) { $profileLoaded = $true } else { $profileLoaded = $false } Write-Output "$sid `t $profilePath `t $profileLoaded" # Load the key if necessary if ($profileLoaded) { $userKeyPath = "HKU:\$sid" } else { $userKeyPath = "HKLM:\TempHive_$sid" & reg.exe load "HKLM\TempHive_$sid" "$profilePath\ntuser.dat" } # DO SOMETHING WITH $USERKEYPATH HERE. ############################################################################################# $hide = (Get-ItemProperty -path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced).Hidden If ($hide -eq 0) { Set-ItemProperty -Path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value "1" } IF ($hide -eq 1) { Set-ItemProperty -Path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value "0" } ############################################################################################## if (!$profileLoaded) { & reg.exe unload "HKLM\TempHive_$sid" } } } Remove-PSDrive -Name HKU ################################################################ $TasknameStop = "ExplorerStop" $TasknameStart = "ExplorerStart" $lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser") SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe" SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" start-sleep -s 1 schtasks /Run /TN $TasknameStop start-sleep -s 1 schtasks /Run /TN $TasknameStart start-sleep -s 1 schtasks /delete /tn $TasknameStop /f schtasks /delete /tn $TasknameStart /f
  23. Install Chocolatey choco install microsoft-teams.install -fvy
  24. Personally I'd change it to a dos batch file rather than powershell, user accont settings are easlry set there.
×
×
  • Create New...