Forskel mellem versioner af "PowerShell"
Fra NørderiWiki
Freesoft (diskussion | bidrag) m (Sæt standard printer) |
Freesoft (diskussion | bidrag) m (→Indstillinger: FuncCheckService) |
||
Linje 56: | Linje 56: | ||
$Printer = Get-WmiObject win32_printer | where {$_.name -match "HP-Printer"} | $Printer = Get-WmiObject win32_printer | where {$_.name -match "HP-Printer"} | ||
$Printer.SetDefaultPrinter() | $Printer.SetDefaultPrinter() | ||
+ | |||
+ | |||
+ | |||
+ | <pre> | ||
+ | |||
+ | function FuncCheckService{ | ||
+ | param($ServiceName) | ||
+ | $arrService = Get-Service -Name $ServiceName | ||
+ | if ($arrService.Status -ne "Running"){ | ||
+ | Start-Service $ServiceName | ||
+ | FuncMail -To "[email protected]" -From "[email protected]" -Subject "Servername : ($ServiceName) service started." -Body "Service $ServiceName started" -smtpServer "relay.mailserver.com" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function FuncMail { | ||
+ | #param($strTo, $strFrom, $strSubject, $strBody, $smtpServer) | ||
+ | param($To, $From, $Subject, $Body, $smtpServer) | ||
+ | $msg = new-object Net.Mail.MailMessage | ||
+ | $smtp = new-object Net.Mail.SmtpClient($smtpServer) | ||
+ | $msg.From = $From | ||
+ | $msg.To.Add($To) | ||
+ | $msg.Subject = $Subject | ||
+ | $msg.IsBodyHtml = 1 | ||
+ | $msg.Body = $Body | ||
+ | $smtp.Send($msg) | ||
+ | } | ||
+ | |||
+ | FuncCheckService -ServiceName "VMware VirtualCenter Server" | ||
+ | |||
+ | </pre> | ||
+ | Fra: http://www.amikkelsen.com/?p=472 | ||
= Tips = | = Tips = |
Versionen fra 19. feb 2013, 08:50
PowerShell er Microsoft's mere eller mindre efter ligning af UNIX's stærke kommandoer. PowerShell er bygget ind i det fleste server programmer fra MS idag, og kan der med administreres med PowerShell.
Indholdsfortegnelse
Active Directory
import-module ActiveDirectory $OU_Name = 'IT' $StartPassword = '123456Pw' New-ADOrganizationalUnit -Name $OU_Name -Path "OU=Users,DC=domain,DC=local" New-ADGroup -Name "$OU_Name-Users" -Path "OU=$OU_Name,OU=Users,DC=domain,DC=local" -groupScope global New-ADOrganizationalUnit -Name Users -Path "OU=$OU_Name,OU=Users,DC=domain,DC=local" import-csv .\"$OU_Name-Brugere.csv" | %{ new-aduser -Name $_.DisplayName -DisplayName $_.DisplayName -GivenName $_.GivenName -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -Surname $_.Surname -Path "OU=Users,OU=$OU_Name,OU=Users,DC=domain,DC=local" -CannotChangePassword $false -ChangePasswordAtLogon $false -ProfilePath "\\server\profiles\$($_.SamAccountName)" -HomeDrive 'Z' -HomeDirectory "\\server\user-homes\$($_.SamAccountName)"; Set-ADAccountPassword -identity $_.SamAccountName -NewPassword (ConvertTo-SecureString -AsPlainText $StartPassword -Force) -Reset; Enable-ADAccount -identity $_.SamAccountName Add-ADGroupMember -Identity "$OU_Name-Users" -Member $_.SamAccountName }
CSV fil:
SamAccountName,UserPrincipalName,GivenName,Surname,DisplayName
IIS
http://learn.iis.net/page.aspx/447/managing-iis-with-the-iis-70-powershell-snap-in/
New-WebVirtualDirectory http://technet.microsoft.com/en-us/library/ee790582.aspx
IIS:\>New-WebVirtualDirectory -Site "Default Web Site" -Name ContosoVDir -PhysicalPath c:\inetpub\contoso
New-Website http://technet.microsoft.com/en-us/library/ee790605.aspx
IIS:\>New-WebSite -Name TestSite -Port 80 -HostHeader TestSite -PhysicalPath "$env:systemdrive\inetpub\testsite"
Fundet på sexchange:
$objIIS = new-object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root") $children = $objIIS.psbase.children $vDir = $children.add("NewFolder",$objIIS.psbase.SchemaClassName) $vDir.psbase.CommitChanges() $vDir.Path = "C:\Documents and Settings\blah\Desktop\new" $vDir.defaultdoc = "Default.htm" $vDir.psbase.CommitChanges()
Indstillinger
Sæt standard printer:
$Printer = Get-WmiObject win32_printer | where {$_.name -match "HP-Printer"} $Printer.SetDefaultPrinter()
function FuncCheckService{ param($ServiceName) $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne "Running"){ Start-Service $ServiceName FuncMail -To "[email protected]" -From "[email protected]" -Subject "Servername : ($ServiceName) service started." -Body "Service $ServiceName started" -smtpServer "relay.mailserver.com" } } function FuncMail { #param($strTo, $strFrom, $strSubject, $strBody, $smtpServer) param($To, $From, $Subject, $Body, $smtpServer) $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = $From $msg.To.Add($To) $msg.Subject = $Subject $msg.IsBodyHtml = 1 $msg.Body = $Body $smtp.Send($msg) } FuncCheckService -ServiceName "VMware VirtualCenter Server"
Fra: http://www.amikkelsen.com/?p=472
Tips
http://myitforum.com/cs2/blogs/rcrumbaker/archive/2006/05/10/20079.aspx
ADSI Scripting with Windows PowerShell
http://larsjoergensen.net/tag/powershell