Set up WSUS to automatically approve security patches (because it’s the right thing to do), [void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”) $wsus = Get-WSUSServer $class = $wsus.GetUpdateClassifications() | ? {$_.Title -In (‘Critical Updates’,’Security Updates’)} $rule = $wsus.GetInstallApprovalRules() | Where {$_.Name -eq “Default Automatic Approval Rule”} $class_coll = New-Object Microsoft.UpdateServices.Administration.UpdateClassificationCollection $class_coll.AddRange($class); $rule.SetUpdateClassifications($class_coll); $rule.Enabled = $True; $rule.Save() $config = $wsus.GetConfiguration(); $config.TargetingMode = […]
Author Archives: Razvan Cosma
list reachable hosts
$ping = New-Object System.Net.NetworkInformation.Ping Get-Content .\list.txt | ForEach-Object { “{0,-15} {1,16}” -f $_,$($($ping.Send($_).Address).IPAddressToString 2>$null) }
convert DHCP IP to static
ESXi %pre –interpreter=busybox # extract network info from bootup VMK_INT=”vmk0″ VMK_LINE=$(localcli network ip interface ipv4 get | grep “${VMK_INT}”) IPADDR=$(echo “${VMK_LINE}” | awk ‘{print $2}’) NETMASK=$(echo “${VMK_LINE}” | awk ‘{print $3}’) GATEWAY=$(esxcfg-route | awk ‘{print $5}’) DNS=”172.16.0.1″ HOSTNAME=$(nslookup “${IPADDR}” “${DNS}” | grep Address | grep “${IPADDR}” | awk ‘{print $4}’) echo “network –bootproto=static –addvmportgroup=true –device=vmnic0 […]
Figure out when a system was installed
AIX: lsconf ll /var/adm/ras/bosinstlog ESXi: get-vmhost | sort name | foreach {$h = $_.Name; $d = (Get-EsxCli -VMHost $h).software.vib.list() | sort InstallDate | select -first 1; write-host $h,$d.InstallDate;} HP-UX: ll /dev/config echo “sel dev 1;info;wait;il”|/usr/sbin/cstm Linux: rpm -qi basesystem rpm -qi filesystem head /var/log/installer/syslog Solaris: showrev ll /var/sadm/system/logs /usr/sbin/prtconf | head Windows: systeminfo | findstr […]
count pages for all docs in a folder
$word = New-Object -ComObject word.application $word.visible = $false $pages = 0 try { Get-ChildItem -path “.” | ? {$_.name -match “.*\.docx{0,1}$”} | foreach-object { write-host $_.name # fullName, confirmConversion, readOnly, addToRecent, passwordDocument $doc = $word.documents.open($_.fullname, $false, $true, $false, “”) $window = $doc.ActiveWindow; $panes = $window.Panes; $pane = $Panes.item(1) $pages += $pane.pages.count $doc.close() write-host $pages } […]
telnet in powershell
If (New-Object System.Net.Sockets.TCPClient -ArgumentList ‘192.168.252.3’,1688) {Write-Host ‘YES’}
increase kvm guest disk
1. add DAG repo 2. yum install libguestfs-tools 3. virt-filesystems –long –parts –blkdevs -h -a w2k8.img (the Windows C: is usually /dev/sda2) 4. dd if=/dev/zero of=w2k8new.img seek=20000 bs=1M count=1 5. virt-resize –expand /dev/sda2 w2k8.img w2k8new.img
powershell – replace text in files
For want of a proper sed, the PS way: Get-ChildItem -exclude *bak | Where-Object {$_.Attributes -ne “Directory”} | ForEach-Object { Copy-Item $_ “$($_).bak”; (Get-Content -Encoding UTF8 $_) -replace “some text”,”other text” | Set-Content -Encoding UTF8 -path $_ }
Solaris – what process is listening on each port?
Since Solaris doesn’t have a ‘netstat -tunlp’, the below parses the output of ptree and pfiles to get a list: my %apps; open(T, “ptree |”); while() { $apps{$1}->{“cmd”}=$2 if(/(\d+)\s+(.*)/) }; close(T); foreach my $p (sort keys %apps) { my @ports; open(F, “pfiles $p 2>/dev/null |”); while() { push(@ports,$1.”/”.$2) if(/sockname.*?AF_INET[6?]\s+(.*?)\s+port: (\d+)/) } my %h=map { $_, […]
re-encode xvid clips for the xbox360 player
# mencoder infile.avi -ovc lavc -oac copy -lavcopts vcodec=mpeg4:threads=2:autoaspect:turbo:mbd=2:trell=1 -ffourcc xvid -mc 0 -vf softskip,harddup -o outfile.avi