Windows Server
127 TopicsHyper-V orphaned or unnecceasry file script
I am trying to create a script that I can run against a Hyper-V cluster or host that can scan and identify orphaned files or files that are unused. THe idea is to clean up a cluster that has a lot of messy files because of migrations, or failed backups, snapshots, etc.5Views0likes0CommentsPowershell 7 getting error updating multi-valued attribute using Set-ADUser. PS 5.1 works
Hi there, I recently moved to PS 7.4 since there is some additional commands related to parallel threads. Now I'm facing an unexpected error due to multivalued updates using Arrays. It says "Invalid type 'System.Collections.ArrayList'" using the following command (that works in previous PS versions): Set-ADUser -identity "user" -Replace @{uid=@("value1","value2")} Already tried many options, like using variable, explicit array declaration and followed Copilot suggestions, but no success yet. It seems like a bug for me. Does anybody knows how to overcome this issue?65Views0likes3CommentsNot able to export AD attribute departmentnumber
Hi, I'm trying to generate a report for all AD users with some AD attributes, such as SamAcconutName, department, departmentnumber, etc. The report is fine with all except departmentnumber. it shows "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" instead of actual number. Here is my PS cmdlet. get-aduser -Properties * | select displayname, departmentnumber | Export-Csv c:\temp\users.csv -NoTypeInformation When tested against a single AD account using the same cmdlet, the screen output shows the value with { }, for example, {123456} instead of 123456. employeenumber attribute worked fine. The same cmdlet shows just the number. Please help, How can I query and export attribute departmentnumber in a report properly? Thanks, Dave96Views0likes4CommentsDoes Microsoft stop support WMIC or WMI?
Hello everyone, Nice to meet you! I heard that MS has plans to deprecate and stop supporting the VB script very soon. I have few queries, please clarify Does Microsoft stop supporting WMIC or WMI along with the VB script? Can we use WMI commands in PowerShell scripts? thanks Madhu46Views0likes1CommentGet command status from Active Directory Domain machines
We need to get the status of few commands from a domain environment of around 400 machines. All may be windows 10 and windows 11 machines. Need to run this activity couple of times in a day. This may required few Power Shell commands with admin credentials OR we may run this from GPO. But I don't know where can we save the status result from machines (Power Shell script running is disabled via GPO so we may need to run PowerShell commands directly) Commands status result are required (windows 10/11): - Last Windows update status - Bit Locker installed and configured status - Total Local Admin users - LAPs is installed on not on machine224Views0likes4CommentsHow do I permanently store module?
Hi everyone, I'm new to powershell, I would like to know how to automatically load the modules I load with import-module in each instance; if I load the modules with import-module, when I close the instance I lose the module. I would like to know how to permanently load, for example, the KPI module in the $Env:PsModulePath variable. Obviously the question is answered to all the modules that I always want to keep in section even when I start the computer. I hope for an answerSolved157Views0likes5CommentsHow do I display a "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" using PowerShell
PS C:\Users\serveradmin.QA> Get-ADDomainController -Filter * | Select-Object Name, OperationMasterRoles |Where-Object {$_.OperationMasterRoles} Name OperationMasterRoles ---- -------------------- ADAICTQA {SchemaMaster, DomainNamingMaster, PDCEmulator, RIDMaster...} in the above command I outputOperationMasterRoles Id like those to be displayed in the same row comma seperated ...how do I disect that ADPropertyValueCollection ?111Views0likes1CommentPowerShell data explanation and advice
Hi everyone. Not even sure how to ask and maybe it seems dramatic but I am reaching out for a little help here. Can someone help me understand this data I copied from PowerShell? I typed the same commands for user "smell" and user "Public". I have a node in network probably and I really hope for the worse to be honest. Reading about it got me pumped. Of course I have no idea if this could be the small window sun shines through or just another big nothing. Anyway, thanks to anyone who sets me straight about it. Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:\Users\smell> whoami / user ERROR: Invalid argument/option - '/'. Type "WHOAMI /?" for usage. PS C:\Users\smell> whoami /user USER INFORMATION ---------------- User Name SID =================== ============================================ thinkpadt16g2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> wmic useraccount where name='smell' get sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where sid='<sid>' get domain,name Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where sid='S-1-5-21-2399413288-642862217-314349489-1001' get domain,name Unexpected switch at this level. PS C:\Users\smell> wmic useraccount get domain,name,sid Domain Name SID ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> Get-WmiObject win32_useraccount | Select domain,name,sid domain name sid ------ ---- --- ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> PS C:\Users\smell> Get-LocalUser | Select-Object -Property @('Name', 'SID') Name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> Get-CimInstance -query 'Select * from win32_useraccount' | ft name, SID name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> C:\Users\Public C:\Users\Public : The term 'C:\Users\Public' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + C:\Users\Public + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Public:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users\Public> C:\Users\Public> : The term 'C:\Users\Public>' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:2 + C:\Users\Public> + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Public>:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users\ C:\Users\ : The term 'C:\Users\' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:2 + C:\Users\ + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users C:\Users : The term 'C:\Users' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:2 + C:\Users + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> PS C:\> Set-Location -PathC:\Users\Public Get-Process : A positional parameter cannot be found that accepts argument 'Set-Location'. At line:1 char:1 + PS C:\> Set-Location -PathC:\Users\Public + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand PS C:\Users\smell> Set-Location -Path C:\Users\Public PS C:\Users\Public> whoami /user USER INFORMATION ---------------- User Name SID =================== ============================================ thinkpadt16g2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> wmic useraccount where name='username' get sid​ Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where name='smell' get sid​ Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where sid='<sid>' get domain,name Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where sid='S-1-5-21-2399413288-642862217-314349489-1001' get domain,name Unexpected switch at this level. PS C:\Users\Public> wmic useraccount get domain,name,sid Domain Name SID ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-WmiObject win32_useraccount | Select domain,name,sid domain name sid ------ ---- --- ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-LocalUser | Select-Object -Property @('Name', 'SID') Name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-CimInstance -query 'Select * from win32_useraccount' | ft name, SID name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public>226Views0likes1CommentPowershell 7 - $time is not defined - Script from Microsoft
I get the error "Get-ADComputer: Variable: 'time' found in expression: $time is not defined.". The script is straight from Microsoft and $time is populated with a date/time. It seems very simple, I don't know what is going wrong. $DaysInactive = 90 $time = (Get-Date).Adddays(-($DaysInactive)) Get-ADComputer -searchbase "OU=SC,OU=Servers,DC=WSDOT,DC=LOC" -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName (edited: correct code to reflect what was being tested)435Views0likes12Commentsshadowcopy
I see when I type wmic /? it shows me wmi options for shadowcopy. Thats great if using the deprecated WMI tool. Leads me to, so I can pull shadowcopy information using WMI tool, what about PS? When I search for shadowcopy with powershell, I find nothing. If there is some shadowcopy hooks in powershell what are they? And can we make them easier to find? seaching all PS docs using below comes up with nothing! Import-Module (Microsoft.PowerShell.Core) - PowerShell | Microsoft Learn\ Thanks! Rod182Views0likes2Comments