{"id":275,"date":"2013-11-19T16:44:53","date_gmt":"2013-11-19T15:44:53","guid":{"rendered":"http:\/\/snakenet.eu\/blog\/?p=275"},"modified":"2014-02-03T16:06:46","modified_gmt":"2014-02-03T15:06:46","slug":"powershell-quelques-commandes-en-vrac","status":"publish","type":"post","link":"https:\/\/snakenet.eu\/blog\/powershell-quelques-commandes-en-vrac\/275\/","title":{"rendered":"PowerShell &#8211; Quelques commandes en vrac"},"content":{"rendered":"<p># Changer le comportement en cas d&rsquo;erreur (get-help about_Preference_Variable)<\/p>\n<pre>$ErrorActionPreference<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">='Inquire'<\/span><\/span><\/span><\/pre>\n<p># OU<\/p>\n<pre>$ErrorActionPreference<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">='Stop'<\/span><\/span><\/span><\/pre>\n<p># Executer une commande a distance (n?cessite que les services soient configur?s via &lsquo;Enable-PSRemoting&rsquo;<\/p>\n<pre>Enter-PSSession<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">HOSTNAME<\/span><\/span><\/span><\/pre>\n<p># Connaitre la version PowerShell<\/p>\n<pre>$PSVersionTable<\/pre>\n<p># Forcer l&rsquo;utilisation d&rsquo;une version sp?cifique de powershell:<\/p>\n<p>powershell<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-version2.0<\/span><\/span><\/span><\/p>\n<p># V?rifier les actions qui seront faites sans les executer r?ellement : # Ajouter le parametre ?WhatIf # Jouer avec la date:<\/p>\n<p>(get-date<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">)<\/span>.<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">addDays(<\/span>-7<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">)<\/span><\/p>\n<p># Faire du caasting de valeur :<\/p>\n<p>[<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">string]$objet<\/span><\/span><\/span><\/p>\n<p># Connaitre TOUTES les donn?es renvoy?es par une fonction.<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Get-Member<\/span><\/span><\/span><\/p>\n<p># Logguer nos actions dans un fichier de log :<\/p>\n<p>Start-Transcript<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">&lsquo;fichierdelog.txt&rsquo;<\/span> Stop-Transcript<\/p>\n<p># Ne choisir que les 3 derniers enregistrements d&rsquo;un tableau de donn?e:<\/p>\n<p>$a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=<\/span><\/span><\/span><span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">get-process <\/span><\/span><\/span>$a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">[-3..-1]<\/span><\/span><\/span><\/p>\n<p># Filtrer les enregistrements: Chercher tous les processus powershell ou powershell_ise dont le temps d&rsquo;occupation CPU a d?pass? 5 secondes.<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Where-Object { (<\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.name <\/span><\/span><\/span>-eq<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;powershell&rsquo;-or$_.name <\/span><\/span><\/span>-eq<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;powershell_ise&rsquo;) <\/span><\/span><\/span>-and<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\"> (<\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.CPU <\/span><\/span><\/span>-gt<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">5 )}<\/span><\/span><\/span><\/p>\n<p># Ne conserver que quelques champs (pas un filtre)<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Select-ObjectName,CPU,ID<\/span><\/span><\/span><\/p>\n<p># Trier les champs dans l&rsquo;ordre inverse<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|sortID-Descending<\/span><\/span><\/span><\/p>\n<p># Aller chercher les valeurs Minimales et Maximales de CPU de certains processus<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-Namesvchost|sort-Objectcpu|select-First1-Last1<\/span><\/span><\/span><\/p>\n<p># Cr?er des champs suppl?mentaires calcul?s<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-Namesvchost|selectname,npm,pm, @{label<\/span><\/span><\/span>=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;Somme&rsquo;;expression<\/span><\/span><\/span>=<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">{<\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.PM <\/span><\/span><\/span>+<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">$_.NPM}}<\/span><\/span><\/span><\/p>\n<p># Boucler sur chaque record.<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-namesvchost|ForEach-Object<\/span><\/span><\/span><\/p>\n<p>#Sauver des donn?es dans un fichier texte<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|out-file&rsquo;fichier.txt&rsquo;<\/span><\/span><\/span><\/p>\n<p>get-process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|select*|out-file&rsquo;fichier.txt&rsquo;<\/span><\/span><\/span><\/p>\n<p># Sauver la liste de tous les services d?marr?s. Ne conserver que les propri?t?s du nom de service ainsi que son statut. Le tout, tri? sur le nom du service par ordre croissant.<\/p>\n<p>Get-Service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|selectname,status|Where-Object { <\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.status <\/span><\/span><\/span>-eq<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">\u00ab\u00a0Running\u00a0\u00bb} <\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">Out-Filelab1.txt<\/span><\/span><\/span><\/p>\n<p># D?marrer tous les services dont le nom commence par la lattre &lsquo;a&rsquo; et afficher sur la console le service qui a ?t? d?marr?.<\/p>\n<p>Get-Service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-name&rsquo;a*&rsquo;|Where-Object { <\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.Status <\/span><\/span><\/span>-ne<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;Running&rsquo; } <\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">ForEach-Object { <\/span><\/span><\/span>$a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=$_.name ; <\/span><\/span><\/span>write-host<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">\u00ab\u00a0Demarrage de $a \u00ab\u00a0; <\/span><\/span><\/span>Start-Service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-name$a}<\/span><\/span><\/span><\/p>\n<p># ou<\/p>\n<p>Get-Service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-name&rsquo;a*&rsquo;|Where-Object { <\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.Status <\/span><\/span><\/span>-ne<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;Running&rsquo; } <\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">ForEach-Object { <\/span><\/span><\/span>$a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=$_.name ; <\/span><\/span><\/span>write-host<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">\u00ab\u00a0Demarrage de $a \u00ab\u00a0; <\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.Start()}<\/span><\/span><\/span><\/p>\n<p># lister les services qui commencent par &lsquo;A&rsquo;:<\/p>\n<p>Get-Service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-name&rsquo;a*&rsquo;<\/span><\/span><\/span><\/p>\n<p># ou<\/p>\n<p>Get-Service|Where-Object<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\"> { <\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.name <\/span><\/span><\/span>-like<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;a*&rsquo; }<\/span><\/span><\/span><\/p>\n<p># g?n?rer un rapport indiquant la liste des processus ayant consomm? plus d&rsquo;une minute de temps CPU. On ne veux que cette valeur et le nom du processus.<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Select-Object<\/span><\/span><\/span>name<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">,cpu<\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">Where-Object { <\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.cpu <\/span><\/span><\/span>-gt<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">1 }<\/span><\/span><\/span><\/p>\n<p># Enregistrer dans un fichier texte les 3 erreurs les plus r?centes du log systeme en ne gardant que la date, le num?ro d&rsquo;erreur, et le message d&rsquo;erreur.<\/p>\n<p>$a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=Get-EventLog<\/span><\/span><\/span>-LogNameSystem?EntryTypeError $a<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">[-3..-1]<\/span><\/span><\/span><\/p>\n<p># ou<\/p>\n<p>Get-EventLog<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-LogNameSystem-EntryTypeError-Newest3<\/span><\/span><\/span><\/p>\n<p># Faire des statistiques<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Measure-Objectcpu,pm-Average-Minimum-Maximum-Sum<\/span><\/span><\/span><\/p>\n<p># Trier des enregistrements, ne sortir que les 4 premiers, mais sauter les 3 premiers<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Sort-Objectcpu-Descending|Select-Object-first4-skip3<\/span><\/span><\/span><\/p>\n<p># Sauver dans un fichier HTML les 10 derniers warnings du log systeme:<\/p>\n<p>Get-EventLog<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-LogNameSystem-Newest10-EntryTypeWarning|ConvertTo-Html|out-file&rsquo;c:\\sample.html&rsquo;<\/span><\/span><\/span><\/p>\n<p># On dispose d&rsquo;une liste de nom de machine dans un fichier texte (1 nom de machine par ligne). On d?sire connaitre l&rsquo;?tat du service &lsquo;bits&rsquo; sur toutes ces machines<\/p>\n<p>Get-Content<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">c:\\liste.txt|ForEach-Object { <\/span><\/span><\/span>get-service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-nameBITS-ComputerName$_ }<\/span><\/span><\/span><\/p>\n<p>#ou<\/p>\n<p>get-service<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-nameBITS-ComputerName (<\/span><\/span><\/span>Get-Content<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">(<\/span>&lsquo;C:\\liste.txt&rsquo;<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">))<\/span><\/p>\n<p>#Envoyer un r?sultat vers 2 directions : TEE<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">powershell*|Tee-Object-variableredirection1|Select-Objectprocessname<\/span><\/span><\/span><\/p>\n<p>$redirection1<\/p>\n<p># Prendre la VALEUR sans l&rsquo;objet (la valeur string par exemple)<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">powershell|select-expandPropertyname<\/span><\/span><\/span><\/p>\n<p># Lier des commandes entre elles.<\/p>\n<p># Si une commande envois des objets et qu&rsquo;il n&rsquo;y a pas de lien entre les noms de propri?t?s et les noms des parametres : Cr?er un LABEL<\/p>\n<p>getADDomainController<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|select*,@{label<\/span><\/span><\/span>=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;ComputerName&rsquo;;expression<\/span><\/span><\/span>=<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">{<\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.hostname}} <\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">get-service-nameDNS<\/span><\/span><\/span><\/p>\n<p># Cr?er un \u00ab\u00a0Drive\u00a0\u00bb connect? sur l&rsquo;AD, la base de registre pour le parcourir comme dans un r?pertoire :<\/p>\n<p>New-PSDrive<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-PSProviderActiveDirectory-nameAD-root&rsquo;ou=sales,dc=domaine,dc=com&rsquo;<\/span><\/span><\/span><\/p>\n<p>set-location<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">AD:<\/span><\/span><\/span><\/p>\n<p># les lister :<\/p>\n<p>Get-PSDrive<\/p>\n<p># Exercice : Cr?er un TREESIZE<\/p>\n<p>Get-ChildItem<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-AttributesD|ForEach-Object {<\/span><\/span><\/span><\/p>\n<p>$taille<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=0<\/span><\/span><\/span><\/p>\n<p>Get-ChildItem<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-path$_.Name <\/span><\/span><\/span>-Recurse<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|ForEach-Object {<\/span><\/span><\/span><\/p>\n<p>$taille<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=$taille+$_.Length<\/span><\/span><\/span><\/p>\n<p>}<\/p>\n<p>Write-Host<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">$_.Name <\/span><\/span><\/span>$taille<\/p>\n<p>}<\/p>\n<p># Sortir la liste complete de TOUTES les propri?t?s de maniere recursive<\/p>\n<p>get-process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Format-Custom<\/span><\/span><\/span><\/p>\n<p># Cr?er des champs CUSTOM.<\/p>\n<p>Get-Process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Format-Table-PropertyName,ID,@{n<\/span><\/span><\/span>=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;VM(MB)&rsquo;;<\/span><\/span><\/span><\/p>\n<p>e=<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">{<\/span>$PSItem<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.VM <\/span><\/span><\/span>\/<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">1MB};<\/span><\/span><\/span><\/p>\n<p>formatString=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;N2&rsquo;;<\/span><\/span><\/span><\/p>\n<p>align=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;right&rsquo;} <\/span><\/span><\/span>-AutoSize<\/p>\n<p># Afficher des donn?es sous forme de tableau graphique interractif<\/p>\n<p>get-process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Out-GridView<\/span><\/span><\/span><\/p>\n<p># Faire une interface graphique de selection de records avant de passer ces elements a autre chose: ##### UTILE #####<\/p>\n<p>get-process<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Out-GridView-PassThru|selectprocessNameCPU<\/span><\/span><\/span><\/p>\n<p># Cr?er un objet COM pour interragir avec<\/p>\n<p>$objetCom<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">=New-Object-ComObjectwscript.network<\/span><\/span><\/span><\/p>\n<p>$objetCom<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">|Get-Member<\/span><\/span><\/span><\/p>\n<p># Bypasser la limitation qui empeche de lancer des scripts (l&rsquo;ordre des parametres a de l&rsquo;importance)<\/p>\n<p>powershell<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-executionpolicyunrestricted-filec:\\script.ps1<\/span><\/span><\/span><\/p>\n<p># Manipuler du WMI<\/p>\n<p>Get-WmiObject<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">Win32_volume|Where-Object {<\/span><\/span><\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.DriveLetter <\/span><\/span><\/span>-eq<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;C:&rsquo;} <\/span><\/span><\/span>|<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">selectDriveLetter,capacity,freespace, @{label<\/span><\/span><\/span>=<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">&lsquo;EspaceLibre (Gb)&rsquo;;expression<\/span><\/span><\/span>=<span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">{<\/span>$_<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">.freespace<\/span><\/span><\/span>\/<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">1GB}}<\/span><\/span><\/span><\/p>\n<p>Get-WmiObject<span style=\"font-size: medium;\"><span style=\"color: #000000;\"><span style=\"font-family: Times New Roman;\">-query&rsquo;SELECT DriveLetter,Freespace FROM win32_volume WHERE DriveLetter=\u00a0\u00bbC:\u00a0\u00bb &lsquo;<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Times New Roman; font-size: medium;\">?<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p># Changer le comportement en cas d&rsquo;erreur (get-help about_Preference_Variable) $ErrorActionPreference=&rsquo;Inquire&rsquo; # OU $ErrorActionPreference=&rsquo;Stop&rsquo; # Executer une commande a distance (n?cessite que les services soient configur?s via &lsquo;Enable-PSRemoting&rsquo; Enter-PSSessionHOSTNAME # Connaitre la version PowerShell $PSVersionTable # Forcer l&rsquo;utilisation d&rsquo;une version sp?cifique de powershell: powershell-version2.0 # V?rifier les actions qui seront faites sans les executer r?ellement : [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":3,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":289,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/275\/revisions\/289"}],"wp:attachment":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}