Returning the Wear counter from a disk - powershell

Just trying to automate some things for my job and I need to report the wear to a txt file that I can later compile into a report that gets emailed.
Having some trouble with getting it to populate the txt file with the wear indication, below is what I'm running and it gives me the variable I want to export to a file
Get-Disk | Where-Object {$_.IsBoot -eq 'True'} | Get-StorageReliabilityCounter | Select Wear
Below is what I'm running that generates the file I need but doesn't actually fill with anything
$DiskWear = Get-Disk | Where-Object {$_.IsBoot -eq 'True'} | Get-StorageReliabilityCounter | Select Wear
$DiskWear.Trim > trimmed.txt
Any help appreciated :)

Related

Script to monitor cpu time for each process for multiple Windows systems

I'm trying to monitor the CPU time for all processes running on multiple computers in order to track down which process could be taxing the CPU at specific times. I'd like to be able to collect the usage and export it to a csv for further review. Here's what I have so far but it only works for a single system. Thanks!
Script:
while ($true) {
Get-Counter '\Process(*)\% Processor Time' | Select-Object -ExpandProperty countersamples| Select-Object -Property instancename, cookedvalue| ? {$_.instanceName -notmatch "^(idle|_total|system)$"} | Sort-Object -Property cookedvalue -Descending| Select-Object -First 10| ft InstanceName,#{L='CPU';E={($_.Cookedvalue/100/$env:NUMBER_OF_PROCESSORS).toString('P')}} -AutoSize
}
I have tried the code above but it is limited to one system and I am unable to export the results for further review.

Custom PowerShell Label script

Asking for a bit of help with my script. I would like to get a list saved to a thumb drive with the computer name and the WAN address. I know I can add a custom label with the computer name but would get the default name. I already set the computer to change the name on reboot but I do not want to reboot as there are other things that need to happen before rebooting. The computers are new and are not added to the domain. I have a thumb drive that will auto-load and assist in changing the name without asking to reboot. So other software can install.
This is what I have so far:
getmac /v /FO CSV | ConvertFrom-Csv | Select-Object #{n='ComputerName';e={$env:COMPUTERNAME}},'Physical Address','Connection Name' | Where-Object { $_.'Connection Name' -Match 'Wi-Fi' }
And this is the output:
ComputerName Physical Address Connection Name
------------------ ------------------ --------------------
Desktop-9K293 XX-XX-XX-XX-XX Wi-Fi
I want the ComputerName to be the new name before rebooting. This way I can add an Export-CSV ~Location\MAC_Report.CSV -NoTypeInformation -append at the end of that code. Is there a way? Or do I need to restart the computer and generate that CSV using the same code?
I would love it to look:
ComputerName Physical Address Connection Name
------------------ ------------------ --------------------
NEW_____Name XX-XX-XX-XX-XX Wi-Fi
There are a lot of things I can make my thumb drive do. This way I have fewer restarts before adding the rest of the software(s) that also requires a restart. This way I cut my restart to one, on both all the software and computer rename.
I ended up just saving a TXT to the desktop of the computer, this way I can add the new computer name manually. This way I can then grab all the text files and consolidate them into one CSV or txt file. A bit of work but at least I can set the restart for later while I am able to install the rest of the software.
getmac /v /FO CSV | ConvertFrom-Csv | Select-Object 'Physical Address','Connection Name' | Where-Object { $_.'Connection Name' -Match 'Wi-Fi' } | Export-CSV -Path "$env:USERPROFILE\Desktop\WLAN_MAC.TXT" -NoTypeInformation
If there was a better way I would have done it.

Removing printer from Devices and Printers with Powershell

I am trying to make a Powershell script that will run in the OU so when the user shuts down their laptop it will remove the local printer and when they turn on their laptop it will re-add and rename the locally attached printer (this will allow the laptops to be docked into different rooms and still use the local printers). The startup script works fine. it re-adds the printer, renames it and sets the trays etc. however the shutdown script doesn't seem to be working correctly.
When the shutdown script is run it removes the printer from device manager/print manager/registry but it still seems to be showing in devices and printer as "driver not available". So when the laptop is started back up the startup script doesn't work as the printer is sitting in error state for the above. a work around is right clicking the printer in devices and printers and pressing "Remove Device" but obviously can not do this during shutdown.
Is there anyway to remove a device from "Devices and Printers" via Powershell? it does work with network printers but just won't fully remove local printers.
$GetDriver = (Get-Printer -Name "Reports" | Select-Object DriverName | ConvertTo-Csv -NoTypeInformation -Delimiter ",") | % {$_ -replace '"',''} | Select-Object -Skip 1
$GetPort = (Get-Printer -Name "Reports" | Select-Object PortName | ConvertTo-Csv -NoTypeInformation -Delimiter ",") | % {$_ -replace '"',''} | Select-Object -Skip 1
Get-Printer -Name "Reports" | Rename-Printer -NewName $GetDriver
Remove-Printer -Name $GetDriver
Remove-PrinterPort -Name $GetPort
Thanks in advance for any help

Office 365 Export proxy addresses from a file of users

Hello I have a csv file that looks like this:
user1#domain.com
user2#domain.com
user3#domain.com
I have been trying to export aliases for each of these users like this:
Import-CSV -Path .\users.txt | ForEach-Object {Get-Mailbox | Select-Object DisplayName,#{Name=“EmailAddresses”;Expression={$_.EmailAddresses | Where-Object {$_ -LIKE “SMTP:*”}}} | Sort | Format-List}
However it appears this script is exporting user info for all users for each line of users. Seems like a simple thing I'm trying to do however I'm not understanding where I've gone wrong here. Any assistance greatly appreciated.
Thanks!

Redirect powershell in batch file works to file but not to null

The following line of code (in a 'Administrator' cmd window on Windows 10) outputs the title of some open windows to the me.txt file, and not to the screen:
POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle" 1>C:\me.txt
But the following line outputs to the screen, even though I say don't:
POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle" 1>NUL
Any ideas?
And I know that there is no point to the command if I am not interested in the result...
[Update] The reason for doing this is because the first time the line is run, it takes almost a second longer than subsequent times, so I wanted to run it once up front to make subsequent times more consistent. In those subsequent runs I do look at the results :-)
Does this produce the expect result? Apologies cannot test as no admin
POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle | Out-Null"