Skip to content

boffnoff/PowerShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerShell

Intune

Uploaded a modified version of 'mark05E' debloater script to the Bloatware folder. Either edit and re-package the PowerShell file or deploy via Intune using the '.intunewim file'

PowerShell deployment scripts

Check and start stopped service

$status=(Get-Service Niagara).Status;
if($status-eq 'Running'){}elseif($status-eq 'Stopped'){Write-Host "The service is stopped.";start-service Niagara;get-service Niagara|Select-object Status}else{Write-Host "The service is in an unexpected state: $status"}

Create shortcut with custom icon

$WshShell = New-Object -comObject WScript.Shell ; $Shortcut = $WshShell.CreateShortcut("C:\Users\public\Desktop\test.url") ; $Shortcut.TargetPath = "https://test.ox.ac.uk/home"
$Shortcut.Save() ; Add-Content -Path "C:\Users\public\Desktop\test.url" -Value "IconFile=C:\Windows\System32\shell32.dll" ; Add-Content -Path "C:\Users\public\Desktop\test.url" -Value "IconIndex=43" ; $Shortcut.Save()

Upload files to Sharepoint

net use r: https://gdsto365.sharepoint.com/sites/XXX/General%20Share/ user:uk\boffnoff
copy "C:\Users\Boffnoff\Downloads\test.txt" r:\somefile.txt

Check running service on entire OU

Get-ADComputer -Filter * -SearchBase "OU=RHS-IT1,OU=RHS-Senior,OU=RHS-Computers,OU=RHSB,OU=Schools,DC=uk,DC=gdst" | Select-Object -ExpandProperty Name | ForEach-Object { $computerName = $_ Invoke-Command -ComputerName $computerName -ScriptBlock { Get-Service -Name 'wuauserv' | Select-Object -Property PSComputerName, Status } } | sort-object PSComputerName

Get AD Description for specific PC

Get-ADComputer -Identity "XX-XX-0005" -Properties * | select-object CN,Description

List updates on selected PCs

$results = invoke-command -computername rhs-wv-0030, rhs-wv-0005 -scriptblock {Get-WmiObject -Namespace "root\ccm\clientsdk" -Class CCM_SoftwareUpdate | Select-Object ArticleID, Name} -credential uk\rhsadmin10
$results | select-object PSComputerName, ArticleID, Name | sort-object PSComputerName

Sort all PCs in OU alphabetically

Get-ADComputer -Filter * -SearchBase "OU=RHS-IT1,OU=RHS-Senior,OU=RHS-Computers,OU=RHSB,OU=Schools,DC=uk,DC=gdst" | select-object Name | sort-object Name

  • Or use the following to filter by name within the OU

    Get-ADComputer -Filter 'Name -like "WT" -SearchBase "etc..."

Bitlocker Domain USB un-lock
  • Setup Bitlocker to auto-unlock for specific domain group/user: (where X is USB drive)

Add-BitLockerKeyProtector -MountPoint "X:" ` -ADAccountOrGroup "uk\rhsadmin10" -ADAccountOrGroupProtector

  • Find out who is currently assigned to that USB:

manage-bde -protectors -get "X:" -Type Identity

SCCM Software Centre Updates
  • list update article and name

Get-WmiObject -Namespace "root\ccm\clientsdk" -Class CCM_SoftwareUpdate | Select-Object ArticleID, Name

  • triggers installation

([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates([System.Management.ManagementObject[]] (get-wmiobject -query 'SELECT * FROM CCM_SoftwareUpdate' -namespace 'ROOT\ccm\ClientSDK'))

Create URL shortcut with custom icon

$WshShell = New-Object -comObject WScript.Shell ; $Shortcut = $WshShell.CreateShortcut("C:\Users\public\Desktop\Oxford-Admissions.url") ; $Shortcut.TargetPath = "https://admissionstesting.ox.ac.uk/candidates" $Shortcut.Save() ; Add-Content -Path "C:\Users\public\Desktop\Online-test.url" -Value "IconFile=C:\Windows\System32\shell32.dll" ; Add-Content -Path "C:\Users\public\Desktop\Online-test.url" -Value "IconIndex=43" ; $Shortcut.Save()

Enable/Disable Bitlocker
  • Disable

@echo off reg add "HKLM\SYSTEM\CurrentControlSet\Policies\Microsoft\FVE" /V RDVDenyWriteAccess /T REG_DWORD /F /D 0

  • Enable

@echo off reg add "HKLM\SYSTEM\CurrentControlSet\Policies\Microsoft\FVE" /V RDVDenyWriteAccess /T REG_DWORD /F /D 1

Check PCs services + start

sc \computername query winrm

OR set to auto startup

sc \computer config winrm start=auto

Uninstall apps

$readerdc= Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "Reader"} ; $readerdc.Uninstall()

Check installed apps on remote PC

$installedapps = Invoke-Command -ComputerName computer01 -Credential uk\USERNAME -ScriptBlock {Get-WmiObject -Class Win32_Product | select Name,Version} ; $installedapps | Out-GridView -Title "Installed Apps"

Install WinGET

invoke-command -computername computer01, computer02 -scriptblock {Add-AppXPackage -Path https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle} -credential uk\USERNAME

Robocopy remote file

$Session = New-PSSession -ComputerName "computer01" -Credential "uk\USERNAME" Copy-Item "Y:\test\folder\file.pdf" -Destination "C:\Users\USER\Desktop" -ToSession $Session

Set SCCM Business hours

Invoke-WmiMethod -Class CCM_ClientUXSettings -Namespace "root\ccm\clientsdk" -Name SetBusinessHours -ArgumentList 16,8,62

Enable auto install SCCM outside of hours

Invoke-WmiMethod -Namespace “Root\ccm\ClientSDK” -Class CCM_ClientUXSettings -Name SetAutoInstallRequiredSoftwaretoNonBusinessHours -ArgumentList @($TRUE)

Fancy shutdown message

shutdown /s /c "Dr.EVIL has initiated a remote restart on your computer"

SANAKO student installer

sanako student installer

Start-Process -wait -FilePath "\uk-rhs-vapps1\Applications\Sanako\v9.32\InstallPrerequisites.exe" Start-Process msiexec.exe -Wait -ArgumentList '/I "\uk-rhs-vapps1\Applications\Sanako\v9.32\KeyboardBlocker.msi" /norestart /quiet' write-host student keyboard-blocker installed, sleeping 3 #wait 5 Start-Sleep -Seconds 3 Start-Process msiexec.exe -Wait -ArgumentList '/I "\uk-rhs-vapps1\Applications\Sanako\v9.32\Student.msi" /norestart /quiet' write-host student msi installed, sleeping 3 #wait 5 Start-Sleep -Seconds 3 Start-Process -FilePath "cmd.exe" -ArgumentList "/c reg.exe import `"\uk-rhs-vapps1\Applications\Sanako\v9.32\Sanako Student.reg""" -Wait -passthru write-host student registry keys imported, sleeping 3 #wait 5 Start-Sleep -Seconds 3 write-host student install complete! Start-Sleep -Seconds 2 Start-Process -wait -FilePath "C:\Program Files (x86)\Sanako\Study\Student\student.exe"

Logoff users

quser logoff 1 (where 1 is the user ID) You can get fancy and use PowerShell sessions Invoke-Command -Session $IT1 -ScriptBlock {logoff 1}

Access NAS / fileserver (PS Drive)

create new-psdrive new-PSDrive -Name "vapps1" -PSProvider "FileSystem" -Root "\servername\share\folder"

PowerShell Session (group PCs with credentials)

$regstatus = @{ ComputerName = 'computer01', 'computer02', 'computer03' ConfigurationName = 'MySession.PowerShell' ScriptBlock = { get-service remoteregistry } } Invoke-Command @regstatus -credential domain\user | out-gridview

macOS

macOS scripts

Check macOS version
sw_vers
Logoff users
sudo pkill loginwindow
Chcek for softwareupdate (and reboot to install)
sudo softwareupdate -i -a -R
Facny popup for users
osascript -e 'display alert "Update macOS" message "Please update macOS software NOW - Dr.EVIL"'

About

PowerShell deployment scripts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors