Get-CimInstance -ClassName Win32_LogicalDisk |
Where-Object DriveType -eq 3 |
Format-Table @{n='DriveLetter';e={$PSItem.DeviceID}},
@{n='FreeSpace(GB)';e={$PSItem.FreeSpace / 1GB};formatString='N2'},
@{n='Size(GB)';e={$PSItem.Size / 1GB};formatString='N2'},
@{n='Type';e={$PSItem.Description};width=5} -AutoSize
Pokazywanie postów oznaczonych etykietą powershell. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą powershell. Pokaż wszystkie posty
czwartek, 19 lutego 2015
czwartek, 22 stycznia 2015
Sprawdzamy czy wszystkie serwery w sieci są dostępne
cls
Write-Host
Write-Host "Checking if PowerShell module for Active Directory is available on this machine..."
$ADModuleAvailable = $null
$ADModuleAvailable = Get-Module -ListAvailable | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleAvailable -eq $null){
Write-Host -ForegroundColor Red "PowerShell module for Active Directory is not available on this machine."
Write-Host -ForegroundColor Red "Please run this script on a domain controller or on a machine that has Active Directory management tools installed."
Write-Host
Exit}
else{
Write-Host -ForegroundColor Green "PowerShell module for Active Directory is availble."}
Write-Host
Write-Host "Checking if PowerShell module for Active Directory is already loaded..."
$ADModuleLoaded = $null
$ADModuleLoaded = Get-Module | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleLoaded -eq $null){
Write-Host "Loading PowerShell module for Active Directory ..."
Import-Module -Name "ActiveDirectory"}
Write-Host -ForegroundColor Green "Powershell module for Active Directory is loaded."
Write-Host
$ServerList = $null
$ServerList = Get-ADComputer -Filter '(OperatingSystem -like "*Server*") -AND (Enabled -ne "False")' -Properties DNSHostName | Select-Object DNSHostName | Sort-Object DNSHostName
$IsOnline = $null
ForEach ($Server in $ServerList) {
$IsOnline = Test-Connection -ComputerName $Server.DNSHostName -BufferSize 10 -Count 1 -Quiet
if ($IsOnline -eq $true){
Write-Host -ForegroundColor Green $Server.DNSHostName "is ONLINE"
}
else {
Write-Host -ForegroundColor Red $Server.DNSHostName "is OFFLINE"
}
}
żródło
Write-Host
Write-Host "Checking if PowerShell module for Active Directory is available on this machine..."
$ADModuleAvailable = $null
$ADModuleAvailable = Get-Module -ListAvailable | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleAvailable -eq $null){
Write-Host -ForegroundColor Red "PowerShell module for Active Directory is not available on this machine."
Write-Host -ForegroundColor Red "Please run this script on a domain controller or on a machine that has Active Directory management tools installed."
Write-Host
Exit}
else{
Write-Host -ForegroundColor Green "PowerShell module for Active Directory is availble."}
Write-Host
Write-Host "Checking if PowerShell module for Active Directory is already loaded..."
$ADModuleLoaded = $null
$ADModuleLoaded = Get-Module | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleLoaded -eq $null){
Write-Host "Loading PowerShell module for Active Directory ..."
Import-Module -Name "ActiveDirectory"}
Write-Host -ForegroundColor Green "Powershell module for Active Directory is loaded."
Write-Host
$ServerList = $null
$ServerList = Get-ADComputer -Filter '(OperatingSystem -like "*Server*") -AND (Enabled -ne "False")' -Properties DNSHostName | Select-Object DNSHostName | Sort-Object DNSHostName
$IsOnline = $null
ForEach ($Server in $ServerList) {
$IsOnline = Test-Connection -ComputerName $Server.DNSHostName -BufferSize 10 -Count 1 -Quiet
if ($IsOnline -eq $true){
Write-Host -ForegroundColor Green $Server.DNSHostName "is ONLINE"
}
else {
Write-Host -ForegroundColor Red $Server.DNSHostName "is OFFLINE"
}
}
żródło
środa, 21 stycznia 2015
Zmiana pliku hosts na kilku komputerach - powershell
Set-ExecutionPolicy Unrestricted
CLS
Import-CSV "d:\Servers.csv" | % {
$Server = $_.ServerName
$adminpath = Test-Path "\\$Server\admin$"
If ($adminpath -eq "True")
{
$hostfile = "\\$Server\c$\Windows\System32\drivers\etc\hosts"
Write-Host –NoNewLine "Updating $Server..."
" 192.168.1.1 mojwpis1" | Out-File $hostfile -encoding ASCII -append
" 192.168.1.1 mojwpis2" | Out-File $hostfile -encoding ASCII -append
Write-Host "Done!"
}
Else
{
Write-Host -Fore Red "Can't Access $Server"
}
}
Plik ServersName:
ServerName
Server1
Server2
CLS
Import-CSV "d:\Servers.csv" | % {
$Server = $_.ServerName
$adminpath = Test-Path "\\$Server\admin$"
If ($adminpath -eq "True")
{
$hostfile = "\\$Server\c$\Windows\System32\drivers\etc\hosts"
Write-Host –NoNewLine "Updating $Server..."
" 192.168.1.1 mojwpis1" | Out-File $hostfile -encoding ASCII -append
" 192.168.1.1 mojwpis2" | Out-File $hostfile -encoding ASCII -append
Write-Host "Done!"
}
Else
{
Write-Host -Fore Red "Can't Access $Server"
}
}
Plik ServersName:
ServerName
Server1
Server2
wtorek, 20 stycznia 2015
Zmiana wielkich liter na małe w Powershell
Wpisujemy:
$string = "ABCD"
$string.toLower()
abcd
Aby zamienić ciąg małych liter na wielkie wpisujemy
$string.toUpper()
poniedziałek, 19 stycznia 2015
Jak sprawdzić jakie kontrolery domeny (AD DC) są w danym drzewie?
W okienku Powershell'a wpisujemy:
$DC_domain =
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$DC_domain.FindAllDomainControllers() | select Name, SiteName, IPAddress | Format-Table
$DC_domain =
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$DC_domain.FindAllDomainControllers() | select Name, SiteName, IPAddress | Format-Table
czwartek, 15 stycznia 2015
Powershell - nie działa skrypt
W oknie Powershell'a wpisujemy:
Get-ExecutionPolicy
Zmieniamy ExecutionPolicy na odpowiadającą nam dostępny poziom polityki wykonywania skryptów:
- Restricted - czyli domyślnie ustawiona polityka w środowisku PowerShell. Jest to najbardziej restrykcyjna polityka pozwalająca tylko na uruchamianie poszczególnych komend. Jedynym wyjątkiem od tej reguły są natywne moduły dedykowane do zarządzania poszczególnymi technologiami Microsoftu.
- AllSigned - czyli polityka pozwalająca już na uruchamianie skryptów, ale tylko tych, które zostały podpisane przez zaufanego wydawcę.
- RemoteSigned - polityka ta pozwala na wykonywanie skryptów z lokalnego komputera bez konieczności ich podpisywania. Jednakże jeśli skrypt pochodzi z Internetu to musi on być podpisany przez zaufanego wydawcę - lub podpisany przez administratora, ale o tym później.
- Unrestricted - Polityka najmniej zalecana, gdyż zezwala na wykonywanie wszystkich skryptów. Posiada jednak drobne zabezpieczenie, mianowicie w przypadku skryptów ściągniętych z Internetu wyświetla się stosowny komunikat o pochodzeniu skryptu.
środa, 19 października 2011
Ustawiamy właściwości okna powershell i cmd dla optymalnej pracy
Po uruchomieniu po raz pierwszy okna powershell lub cmd, możemy być zadowoleni z jego rozmiarów. Powyżej zamieszczam moje typy wartości które należy ustawić we właściowościach.
Subskrybuj:
Posty (Atom)
