Geeks With Blogs

Lance's TextBox

Here are a few one-liners that use NetCmdlets. Some of these I've blogged about before, some are new. Let me know if you have questions, which ones you find useful, or how you altered these to suit your own needs.

  1. Send email to a list of recipient addresses:

    import-csv users.csv | % { send-email -to $ -from -subject "Important Email" –message "Hello World!" -server }
  2. Show the access control list for a specific Exchange folder:

    get-imap -server $mymailserver -cred $mycred -folder INBOX.RESUMES –acl
  3. Add look and read permissions on an Exchange folder, for a list of accounts pulled from a CSV file:

    import-csv users.csv | % { set-imap -server -acluser $_.username $mymailserver -cred $mycred -folder INBOX.RESUMES –acl “lr”  }
  4. Sync system time with an Internet time server:

    get-time -server –set

    To remotely sync the time on a set of computers:

    import-csv computers.csv | % { Invoke-Command -computerName $ -cred $mycred -scriptblock { get-time -server –set } }
  5. Delete all emails from an Exchange folder that match a certain criteria.  For example, delete all emails from

    get-imap -server $mailserver –cred $mycred | ? {$_.FromEmail -eq} | %{ set-imap -server $mailserver –cred $mycred-message $_.Id -delete }
  6. Update Twitter status from PowerShell:

    get-http –url "" –cred $mycred -variablename status -variablevalue "Tweeting with NetCmdlets!"
  7. A test-path that works over FTP, FTPS (SSL), and SFTP (SSH) connections:

    get-ftp -server $remoteserver –cred $mycred -path /remote/path/to/checkfor*

    Don't forget the *.  Also, to use SSL or SSH just add an –ssl or –ssh parameter.
  8. List disabled user accounts in Active Directory (or any other LDAP server):

    get-ldap -server $ad -cred $mycred -dn dc=yourdc -searchscope wholesubtree
        -search "(&(objectclass=user)(objectclass=person)(company=*)(userAccountControl:1.2.840.113556.1.4.803:=2))"
  9. List Active Directory groups and their members:

    get-ldap -server testman -cred $mycred -dn dc=NS2 -searchscope wholesubtree -search "(&(objectclass=group)(cn=*admin*))" | select ResultDN, member
  10. Display the last initialization time (e.g. last reboot time) of all discoverable SNMP agents on a network:

    import-csv computers.csv | % { get-snmp -agent $ -oid sysUpTime.0 | %{([datetime]::Now).AddSeconds(-($_.OIDValue/100))} }

Not mentioned here:  data conversion (Yenc, QP, UUencoding, MD5, SHA1, base64, etc), DNS, News Groups (NNTP/UseNet), POP mail, RSS feeds, Amazon S3, Syslog, TFTP, TraceRoute, SNMP Traps, UDP, WebDAV, whois, Rexec/Rshell/Telnet, Zip files, sending IMs (Jabber/GoogleTalk/XMPP), sending text messages and pages, ping, and more.


Posted on Tuesday, December 29, 2009 4:36 AM PowerShell | Back to top

Comments on this post: 10 PowerShell One Liners

# re: 10 PowerShell One Liners
Requesting Gravatar...
Pretty cool - just a matter of time before the Linux side switches over ;-)
Left by Charlie Page on Mar 20, 2011 12:17 AM

Your comment:
 (will show your gravatar)

Copyright © Lance Robinson | Powered by: