Need help to remove default Windows 10 apps via powershell - windows

I'm trying to debloat Windows 10 Education by running the following commands in a powershell script. I can get the script to remove the apps for the logged in user but as soon as someone new logs in, the apps reappear.
Here is my script:
Get-AppxPackage -AllUsers | where-object {$_.name –like “*3DBuilder*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowsalarms*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowscamera*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowscommunicationsapps*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*officehub*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*getstarted*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowsmap*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*solitairecollection*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*bingfinance*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*bingnews*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*zunevideo*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*people*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowsphone*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*bingsports*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*windowsstore*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*soundrecorder*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*bingweather*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*xboxapp*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*Appconnector*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*MinecraftUWP*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*Messaging*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*WindowsFeedbackHub*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*Getstarted*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*GetHelp*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*ContactSupport*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*Wallet*”} | Remove-AppxPackage
Get-AppxPackage -AllUsers | where-object {$_.name –like “*OneConnect*”} | Remove-AppxPackage
Any advice would be much appreciated.

I'm not 100% sure but I think you need to use the -Online parameter
$Apps = Get-AppxProvisionedPackage -Online
$Apps | Where-Object {$_.DisplayName -like "*windowscommun*"} | Remove-AppxProvisionedPackage -Online

You've got the -AllUsers switch set on Get-AppxPackage, but not on Remove-AppxPackage. If you do add it to the end of each line, you should get the expected behavior. Note that I don't think you need the first AllUsers switch, but it can't hurt to keep it in (excluding that it'll probably make the commands take longer to complete.)
Get-AppxPackage -AllUsers | where-object {$_.name –like “*3DBuilder*”} | Remove-AppxPackage -AllUsers

Related

How to get drive letter by using serialnumber in windows powershell?

Below is the code i have used to get driveletter using the serialnumber
Get-CimInstance -ClassName Win32_DiskDrive |
Get-CimAssociatedInstance -Association Win32_DiskDriveToDiskPartition |
Get-CimAssociatedInstance -Association Win32_LogicalDiskToPartition
Where-Object VolumeSerialNumber -eq "66B78EE4" | Select-Object DeviceID
Get-CimAssociatedInstance -Association Win32_LogicalDiskToPartition |
Select-Object -Property SerialNumber
Get-Volume
Please help this in getting the driveletter using serialnumber

what is the error in the powershell script?

I have run the below command to get the output that when was my machine last patched but also need how to get the KB details too and how can I export in csv from SCCM.
$lastpatch=Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object HotfixID, InstalledOn | Select-Object -first 1
"{0:MM/dd/yyyy}" -f $lastpatch.InstalledOn | Write-Output
When I run the below command to also get the HotfixID but I am not getting the result so can someone help me with it.
$lastpatch= Get-HotFix | Sort-Object InstalledOn -Descending | select-object -first 1 | Select-Object InstalledOn, HotfixID
"{0:MM/dd/yyyy}" -f $lastpatch.InstalledOn,$lastpatch.HotfixID | Write-Output
To include the HotfixID, you can make use of a calculated property to have the Select-Object return an object with both wanted properties into the variable $lastPatch.
Once you have that object, it is easy to export to csv:
$lastpatch = Get-HotFix |
Sort-Object InstalledOn -Descending |
Select-Object -First 1 |
Select-Object #{Name = 'InstalledOn'; Expression = {"{0:MM/dd/yyyy}" -f $_.InstalledOn}},
HotfixID
# Output on screen
$lastPatch
# output to csv file
$lastPatch | Export-Csv -Path 'Path\To\lastpatch.csv' -UseCulture -NoTypeInformation

Powershell where-object not playing well with PSdrive

I'm trying to exclude two drives from a file search. I'm getting an error when running the code: "Get-ChildItem : Access to the path 'C:\Windows\system32\LogFiles...'". The search shouldn't touch C. Help!! What am I doing wrong? Code attached.
$Drives = Get-PSDrive -PSProvider FileSystem | where { -not ('c','u' -eq $_.name) }
$FS='(.*18)\.FOO'
$FPath=#(foreach($Drive in $drives) {
Get-ChildItem -Path $Drive.Root -Recurse | Where-Object {$_.Name -match $FS} -ErrorAction SilentlyContinue | %{$_.Name}
})
I think you are looking for
Get-PSDrive -PSProvider FileSystem |
Where-Object {"c","u" -notcontains $_.name} |
ForEach-Object{
Get-ChildItem -Path $_.Root -Recurse |
Where-Object {$_.Name -match '(.*18)\.FOO'} -ErrorAction SilentlyContinue |
select Name
}
Seems based on your comments you are still getting the error. Lets trouble shoot it a bit. Lets output the drive that it really seems to error on.
Get-PSDrive -PSProvider FileSystem |
Where-Object {"c","u" -notcontains $_.name} |
ForEach-Object{
$Drive = $_.Name
try{
Get-ChildItem -Path $_.Root -Recurse |
Where-Object {$_.Name -match '(.*18)\.FOO'} -ErrorAction SilentlyContinue |
Select Name
}catch{
#{
Drive = $Drive
}
}
}

output results from a Powershell script [duplicate]

How do I properly use $_ in out-file? Here's my code:
get-content computers.txt |
Where {$_ -AND (Test-Connection $_ -Quiet)} |
foreach { Get-Hotfix -computername $_ } |
Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
convertto-csv | out-file "C:\$_.csv"
I'm trying to execute a get-hotfix for all the computers listed in the text file then I want them to be exported to CSV with the computer name as the filename.
You need one pipeline to process the computers.txt files, and a nested one inside the foreach to process the list of hotfixes for each computer:
get-content .\computers.txt |
Where {$_ -AND (Test-Connection $_ -Quiet)} |
foreach {
Get-Hotfix -computername $_ |
Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
convertto-csv | out-file "C:\$_.csv"
}
Edit: Changed computers.txt to .\computers.txt, as this is required for local paths in powershell
i can see with this:
get-content .\computers.txt | Where {$_ -AND (Test-Connection $_ -Quiet)} | foreach{ Get-Hotfix -id KB4012212 -computername $_ | Select CSName,Description,HotFixID,InstalledBy,InstalledOn | convertto-csv | out-file "C:\$_.csv" }
i can see only in which PC is the fix (KB4012212) installed.
it's possible to see the following
CSNAME Fix(Inst/NotInst)
PC1 FIxInstalled
PC2 FixNotinstalled
PC3 FixnotInstalled
..
..
etc
I monkeyed with this for a while and nothing I found on-line worked until I used this combo. 
I used the method is this thread but it was SO slow and I wanted to learn more about using jobs so this is what ended up working for me on Windows 7 PS Ver 4.
All other options were either too slow or did not return data from the remote system.
$VMs = get-content C:\WinVms.txt #Generate your hostnames list however you deem best.
foreach ($vm in $vms)
{
Write-Host "Attempting to get hotfixes on:" $vm
invoke-command -computername $vm -ScriptBlock {start-job -scriptblock {(get-hotfix | sort installedon)[-1]} | wait-job | receive-job} -AsJob
}
start-sleep 60 # give it a minute to complete
get-job | ? { $_.state -eq "Completed"} | receive-job -keep | export-csv c:\temp\win-patch.csv
you can check your failures too like this: 
get-job | ? { $_.state -eq "Failed"}

powershell networkinterface convert bytes to kilobytes

I want to convert unit that bytes to kilobytes.
powershell command of bellow entered :
Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |
select BytesReceivedPersec , BytesSentPersec , name |
Where-Object {$_.name -cnotmatch "isatap"} |
Where-Object {$_.name -cnotmatch "Teredo"} |
Where-Object {$_.name -cnotmatch "로컬"} |
% { '{0,10} {1,20} {2,20}' -f $_.BytesReceivedPersec, $_.BytesSentPersec , $_.name}
output :
627975 483072 Intel[R] 82575L Gigabit Network Connection
But output unit is Bytes
I want to convert unit that bytes to kilobytes.
Add /1kb to the BytesReceived expression and surround them with parentheses:
Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |
select BytesReceivedPersec , BytesSentPersec , name |
Where-Object {$_.name -cnotmatch "isatap|Teredo|로컬"} |
% { '{0,10} {1,20} {2,20}' -f ($_.BytesReceivedPersec /1kb), ($_.BytesSentPersec /1kb) , $_.name}
Also you can use -cnotmatch {"isatap|Teredo|로컬"} to short the code

Resources