$MyApp = gwmi win32_product | ? {$_.name -match ‘Acrobat’}
$MyApp.Uninstall()
Category Archives: PowerShell
Wysyłanie wiadomość użytkownikom Windows przez PowerShell. Sending message to Windows User via Powershell
To send message to Windows user via Powershell first we have to login to remote computer using PowerShell remoting (how to: http://obsluga-it.pl/powershell-remoting/) and put command:
msg console /server:localhost "Prosimy zapisać otwarte dokumenty i zrestartować komputer. Dziękujemy. Dział Informatyki."
Windows Server 2012 R2 – konwersja z wersji Server Full do wersji Core i odwrotnie
Konwersja z Windows Server 2012 R2 do wersji Windows Server 2012 R2 Core:
Remove-WindowsFeature server-gui-shell,server-gui-mgmt-infra
Konwersja z Windows Server 2012 R2 Core do Windows Server 2012 R2:
Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
PowerShell remoting
Wymagania dot. zdalnego połączenia przez PS:
- Otwarte porty: WSMan: 5985. Jeżeli połączenie ma się odbywać przez SSL, otwarty również port 5986;
- Sieć nie publiczna: Prywatna lub Firmowa;
- Uruchomiona usługę WinRM, skonfigurować uruchamianie w auto starcie;
- Utworzony Listenera dla adresu IP lub nazwy komputera.
Uruchomienie PS Remoting na komputerach pracujących w domenie:
- Konfiguracja auto startu usługi:
Computer Configurations / Windows Settings / Security Settings / System Services / Windows Remote Management (WS-Management), - Konfiguracja Listenera:
Computer Configurations / Administrative Templates / Windows Components / Windows Remote Managament (WinRM) / WinRM Service
Opcja skonfigurowana na Enable, w miejscu IPv4 filter gwiazdka (*) - Konfiguracja zapory sieciowej:
Computer Configurations / Windows Settings / Security Settings / Windows Firewall with Advanced Security / Inbound Rules
Zamiast klikologii można posłużyć się komendami Powershell. Na maszynie, do której mamy się łączyć należy otworzyć PS z podwyższonymi uprawnieniami i wydać następujące komendy:
$Interface_Index = Get-NetConnectionProfile | Select -ExpandProperty InterfaceIndex Set-NetConnectionProfile -InterfaceIndex $Interface_Index -NetworkCategory Private Enable-PSRemoting -Force Restart-Service WinRM
Dodatkowo na komputerze z którego mamy się łączyć do innych maszyn należy uruchomić PS z podwyższonymi uprawnieniami i wydać następującą komendę:
Set-Item wsman:\localhost\client\trustedhosts *
Samo połączenie do zdalnego komputera odbywa się poprzez wydanie polecania:
Enter-PSSession -ComputerName 192.168.5.7 -Credential admin
Możliwe jest wykonanie skryptu lub komendy na wielu komputerach naraz poprzez polecenie:
Invoke-Command -ComputerName 192.168.5.7, 192.168.5.8 -ScriptBlock { Get-ChildItem C:\ } -credential admin_account_name
lub uruchomiś skrypt PowerShell:
Invoke-Command -ComputerName 192.168.5.7, 192.168.5.8 -FilePath C:\skrypty\tajemniczy_skrypt.ps1
http://powershell.org/wp/2012/08/06/ebook-secrets-of-powershell-remoting/
http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/29/remoting-week-non-domain-remoting.aspx
Windows Server 2012 R2 Core – konfiguracja NIC Teaming
powershell Get-NetAdapter Get-NetAdapter ethernet0 | fl *
fl od format list – wszystkie właściwości interfejsu.
Następnie należy wyłączyć na jednym interfejsie usługę DHCP Client i nadać mu statyczny adres IP.
Get-NetAdapter ethernet0 | Set-NetIPInterface -dhcp disabled Get-NetAdapter ethernet0 | new-netipaddress -IPAddress 192.168.0.104 -DefaultGateway 192.168.0.1 -PrefixLenght 24 Set-DNSClientServerAddress -InternetAlias ethernet0 -ServerAddress 192.168.0.100
Po nadaniu adresu IP jednemu interfejsowi można rozpocząć konfiguracją funkcji NIC Teaming
new-netbfoteam -name "Nasz Team" -TeamMembers ethernet0,ethernet1 -TeamingMode switchindependent -LoadBalancingAlgorithm dynamic
Nazwa netbfoteam pochodzi od Net Balance and Fail Over Team.
Teraz wynik komendy Get-NetAdapter pokaże 3 interfejsy – 2 interfejsy sieciowe fizyczne, oraz interfejs „Nasz Team”, który możemy konfigurować jak fizyczny interfejs (adresacja IP itp.).
PowerShell – włączenie Windows PowerShell Web Access (PSWA) w Windows 2012 R2
Enable-PSRemoting -SkipNetworkProfileCheck Install-WindowsFeature WindowsPowerShellWebAccess -IncludeAllSubFeature -IncludeManagementTools Install-PswaWebApplication –WebSiteName "Default Web Site" –WebApplicationName "PSWA" –UseTestCertificate Add-PswaAuthorizationRule -UserName server\Administrator -ComputerName server -ConfigurationName Microsoft.PowerShell Add-PswaAuthorizationRule -UserName win2k8r2\Administrator -ComputerName win2k8r2 -ConfigurationName Microsoft.PowerShell