[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-572515-105":3,"detail-sidebar-cat-1-en-105":81,"doc-detail-572515-en":127},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","powershell-cheat-sheet-quick-reference","PowerShell Cheat Sheet - Quick Reference","","PowerShell Cheat Sheet provides concise, practical reminders for common scripting tasks. It covers variable syntax and automatic variables, supported operators, and how to escape special characters with the backtick. It explains output handling via Write-Host and Write-Output, typing and type casts, arrays and hash tables, and object creation with New-Object. It also documents error handling patterns (throw, try/catch/finally), function definitions, argument passing, loops and conditionals, pipeline filtering, cmdlet discovery, and script parameters and dot-sourcing.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/general/","General",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/powershell-cheat-sheet-quick-reference/572515/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/powershell-cheat-sheet-quick-reference/572515.png","ImageObject",442,249,{"name":42,"@type":43},"Riley West","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-20","2026-10-13",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",7,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"How do I define and use variables in PowerShell?","Question",{"text":63,"@type":64},"Precede variable names with $. Example syntax like $variableName = \"value\" is used, and special cases like wrapping member access with $() are highlighted.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"Which operators are used for comparisons and logical logic in PowerShell?",{"text":68,"@type":64},"The cheat sheet explains that traditional equality/comparison operators are limited and lists PowerShell operators such as -eq, -ne, -lt, -le, -gt, -ge, -and, -or, -not, plus bitwise variants like -band and -bor.",{"name":70,"@type":61,"acceptedAnswer":71},"What is the recommended way to handle errors in PowerShell scripts?",{"text":72,"@type":64},"Use the throw keyword to raise errors, and use try/catch/finally to catch exceptions. The error object in the catch block is referenced through $_.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},572515,1792087007,{"code":4,"msg":82,"data":83},"success",[84,89,94,99,104,109,114,119,124],{"id":85,"doc_module":22,"doc_module_name":25,"category_name":86,"show_sort_weight":87,"slug":88},11,"Presentations",90,"presentations",{"id":90,"doc_module":22,"doc_module_name":25,"category_name":91,"show_sort_weight":92,"slug":93},12,"Resumes",80,"resumes",{"id":95,"doc_module":22,"doc_module_name":25,"category_name":96,"show_sort_weight":97,"slug":98},14,"Invoices",70,"invoices",{"id":100,"doc_module":22,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},15,"Posters",60,"posters",{"id":105,"doc_module":22,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},16,"Social Media",50,"social-media",{"id":110,"doc_module":22,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},17,"Forms",40,"forms",{"id":115,"doc_module":22,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},18,"Letters",30,"letters",{"id":120,"doc_module":22,"doc_module_name":25,"category_name":121,"show_sort_weight":122,"slug":123},21,"Paper Templates",5,"papers-templates",{"id":125,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":4,"slug":126},158,"general-158",{"code":4,"msg":82,"data":128},{"doc_id":79,"user_id":129,"nickname":42,"user_avatar":130,"doc_module":22,"category_id":125,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":131,"file_id":132,"file_url":133,"file_type":134,"file_size":135,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":22,"language":136,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":12,"update_tm":140,"read_time":4},1099523885074,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","| Category | Description | Examples |\n| --- | --- | --- |\n| Variable | Precede all variable names with $ | $variableName = \"variable value\" |\n| Automatic\u003Cbr>Variables | Variables that are created at runtime based on context. | \u003Cbr>|\n| Operators | Traditional equality, comparison, and logical operators cannot be used (except for “!”) . | \u003Cbr>== != \u003C \u003C= > >= && || ! & | ^\u003Cbr>-eq -ne -lt -le -gt -ge -and -or -not (or !) -band -bor -xor |\n| Escape Character | Use the backward tick to escape special characters such as quotes and the dollar sign. | $text = \"Tessa says `\"hello!`\"\" >> Tessa says \"hello!\"\u003Cbr>$pwd = \"pa`$`$w0rd\" >> pa$$w0rd |\n| Write Output | Use Write-Host to dump to the console. Use Write-Output to dump to the pipeline. When accessing variable members wrap in $() . | Write-Host \"It's a great day to learn PowerShell!\"\u003Cbr>Write-Host \"Storage = $($site.Usage .Storage/1MB)MB\"\u003Cbr>Write-Output $site |\n| Types | Surround type name with square brackets. Some common data types are aliased for brevity. | [Microsoft .SharePoint.SPBasePermissions]\u003Cbr>[xml], [int], [string], [bool], etc. |\n| Statics | Call static members by separating the type and member by two colons. | [Microsoft .SharePoint.SPBasePermissions]::ManageWeb\u003Cbr>[Microsoft .SharePoint.Administration.SPFarm]::Local\u003Cbr>[Microsoft .SharePoint.Publishing.PublishingWeb]::GetPublishingWeb ($web) |\n| Type Cast | Precede variable name with type or use-as operator. PowerShell can also do a lot of implicit type casting. | [Microsoft .SharePoint.SPBasePermissions]\"ManageWeb\"\u003Cbr>$perm = \"ManageWeb\" -as [Microsoft.SharePoint .SPBasePermissions]\u003Cbr>[xml]$xml = \"\u003CSite Url='[http://demo](http://demo) ' />\"\u003Cbr>$roleDefinition.BasePermissions = \"ViewListItems\",\"AddListItems\" |\n| Arrays | Comma separate values. Declare using @() . | $perms = \"ManageWeb\", \"ManageSubwebs\"\u003Cbr>$perms = @()\u003Cbr>$perms += \"ManageLists\"\u003Cbr>$perms += \"ManageWeb\", \"ManageSubwebs\" |\n| Hash Tables | Declare using @{} . Separate key/value pairs with a semicolon. Values can include script blocks. | $values = @{Url=\"[http://demo](http://demo)\"; OwnerAlias=\"Aptillon\\glapointe\"}\u003Cbr>$values += @{Template=\"STS\\#0} |\n| Creating Objects | Use the New-Object cmdlet (pass constructor args as an array) .\u003Cbr>Pivot a hash table using the PSObject type. | $field = New-Object Microsoft.SharePoint.SPFieldText $fields, \"Text\", $fieldName\u003Cbr>$obj = New-Object PSObject -Property $hash |\n| Throw Errors | Use the throw keyword. | throw \"An unknown error occurred.\" |\n| Catch Errors | Use the try/catch/finally keywords. $_represents the error object in the catch block. Add an optional type after the catch keyword to catch a specific exception (you can have multiple catch blocks) . | $web = Get-SPWeb [http://demo](http://demo)\u003Cbr>[try](try {)[ {](try {)\u003Cbr>$list = $web .GetList( \"Foo List\" )\u003Cbr>} catch {\u003Cbr>Write-Warning \"Could not find list. $($_ .Exception.Message)\"\u003Cbr>} finally { $web .Dispose() } |\n| Functions | Declare using the function keyword. Arguments are comma separated and wrapped in parenthesis. Function body is wrapped in curly braces. | function Get-SPGroup (\u003Cbr>[Microsoft .SharePoint.PowerShell.SPWebPipeBind]$web,[string]$group) {\u003Cbr>$spWeb = $web.Read()\u003Cbr>$spGroup = $spWeb.SiteGroups[$group]\u003Cbr>$spWeb .Dispose()\u003Cbr>return $spGroup\u003Cbr>} |\n| Passing Script /\u003Cbr>Function Args | No commas or parenthesis. Positional or named. PowerShell script and function parameters only! | $group = Get-SPGroup \"[http://demo](http://demo)\" \"Demo Owners\"\u003Cbr>$group = Get-SPGroup -Web [http://demo](http://demo -Group)[ -Group](http://demo -Group) \"Demo Owners\" |\n| Loops | The do/while, while, for, and foreach loops are built-in constructs. ForEach-Object (aliased as foreach and %) is a cmdlet (use $_ for the current object) . ForEach-Object does not support break or continue statements. | do { Start-Sleep 2 } while ( ! (Get-SPSolution $name) .Deployed)\u003Cbr>while ( ! (Get-SPSolution $name) .Deployed) { Start-Sleep 2 }\u003Cbr>foreach ($site in (Get-SP","cbCaiu2IwrODLXAk","https://ap.wps.com/l/cbCaiu2IwrODLXAk","pdf",668010,"English","# Variable Syntax\n## Output and Typing\n## Arrays and Hash Tables\n## Objects and Error Handling\n## Functions, Loops, and Conditionals\n## Pipeline Filtering and Cmdlet Discovery\n## Parameters and Dot-Sourcing","[{\"question\":\"How do I define and use variables in PowerShell?\",\"answer\":\"Precede variable names with $. Example syntax like $variableName = \\\"value\\\" is used, and special cases like wrapping member access with $() are highlighted.\"},{\"question\":\"Which operators are used for comparisons and logical logic in PowerShell?\",\"answer\":\"The cheat sheet explains that traditional equality/comparison operators are limited and lists PowerShell operators such as -eq, -ne, -lt, -le, -gt, -ge, -and, -or, -not, plus bitwise variants like -band and -bor.\"},{\"question\":\"What is the recommended way to handle errors in PowerShell scripts?\",\"answer\":\"Use the throw keyword to raise errors, and use try/catch/finally to catch exceptions. The error object in the catch block is referenced through $_.\"}]","PowerShell Cheat Sheet - Quick Reference | PDF",1791927829]